Reputation: 1384
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:
home.php?id=services to look like domain.com/services
(this for
multiple links/URLs) - Works finehome.php?id=blog&year=2013&month=12
to look like
domain.com/blog/year2013/month12
Works finehome.php?id=blog&slug=this-is-a-blog-post
to look like
domain.com/blog/this-is-a-blog-post
Works finehome.php?id=status&cat=123
to be domain.com/status/cat123
Not workinghome.php?id=blog&seq=456
to be domain.com/status/456
Not workingas 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?
Upvotes: 2
Views: 2266
Reputation: 786289
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]
Upvotes: 3