2

I have these mod rewrite rules in my htaccess file:

RewriteEngine On

# Displays directory if there is no / on the end of the URL
RewriteCond %{REQUEST_URI} !^/admin [NC]
RewriteCond %{REQUEST_URI} !^/status [NC]
RewriteCond %{REQUEST_URI} !^/customer [NC]

# Removes index.php from URL 
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]

# Rewrites /services to be /index.php?id=services
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)/?$ /index.php?id=$1 [L,QSA]

# Rewrites /blog/this-is-a-blog-post to be /index.php?id=blog&slug=this-is-a-blog-post
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)/([\w-]+)/?$ /index.php?id=$1&slug=$2 [L,QSA]

# Rewrites /blog/year2013/month12 to be /index.php?id=blog&year=2013&month=01
RewriteRule ^([a-zA-Z0-9-]+)/year([0-9]+)/month([0-9]+)/?$ /index.php?id=$1&year=$2&month=$3 [L,QSA]

# Rewrites /status/123 to be /index.php?id=status&seq=123
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)/([\w-]+)/?$ /index.php?id=$1&seq=$2 [L,QSA]

# Rewrites /status/cat1 to be /index.php?id=status&cat=1
RewriteRule ^([a-zA-Z0-9-]+)/cat([0-9]+)?$ /index.php?id=$1&cat=$2 [L,QSA]

the /blog works fine, but /status doesn't. its showing the directory index of even tho there is no directory

i basically want:

  1. home.php?id=services to look like domain.com/services (this for multiple links/URLs) - Works fine
  2. home.php?id=blog&year=2013&month=12 to look like domain.com/blog/year2013/month12 Works fine
  3. home.php?id=blog&slug=this-is-a-blog-post to look like domain.com/blog/this-is-a-blog-post Works fine
  4. home.php?id=status&cat=123 to be domain.com/status/cat123 Not working
  5. home.php?id=blog&seq=456 to be domain.com/status/456 Not working

as you can see above only numbers 4 and 5 don't work, they are just showing either index of or 404 page not found however there is no directory stored on the web server with a name of status

how can I fix my code above to get this working as the list above?

1 Answer 1

3

You need to change regex in /status/123 rule to make it capture only numbers and hyphens and bring /blog/this-is-a-blog-post rule below it.

Use this code:

Options +FollowSymLinks -MultiViews
RewriteEngine On

# Displays directory if there is no / on the end of the URL
RewriteCond %{REQUEST_URI} !^/(admin|status|customer) [NC]
# Removes index.php from URL 
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]

# Rewrites /services to be /index.php?id=services
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)/?$ /index.php?id=$1 [L,QSA]

# Rewrites /blog/year2013/month12 to be /index.php?id=blog&year=2013&month=01
RewriteRule ^([a-zA-Z0-9-]+)/year([0-9]+)/month([0-9]+)/?$ /index.php?id=$1&year=$2&month=$3 [L,QSA]

# Rewrites /status/123 to be /index.php?id=status&seq=123
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)/([\d-]+)/?$ /index.php?id=$1&seq=$2 [L,QSA]

# Rewrites /blog/this-is-a-blog-post to be /index.php?id=blog&slug=this-is-a-blog-post
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)/([\w-]+)/?$ /index.php?id=$1&slug=$2 [L,QSA]

# Rewrites /status/cat1 to be /index.php?id=status&cat=1
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^([a-zA-Z0-9-]+)/cat([0-9]+)?$ /index.php?id=$1&cat=$2 [L,QSA]
Sign up to request clarification or add additional context in comments.

3 Comments

When I go to domain.com/status/cat1 I just shows /status page but if I do /status?cat=1 that works fine. When it shows index.php?id=status it includes status.php so the actual page it is showing is status.php?cat=1
Check my update. Not sure if my above comment made sense
Alright provably I misunderstood some of your retirement. Request you to please provide the URLs that don't work in your question and I will test it out once I get back to my computer and update my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.