2
votes

I have a blog page on my website and .htaccess is as below to convert SEO Friendly URL

RewriteRule ^([^/.]+)/?$ /blogdetail?prmn=$1 [L]

So, my URL becomes http://example.com/title-of-blog and it is working pretty fine and awesome but my client reported today that admin section is not working properly and i checked and found that URL http://example.com/admin is getting converted to http://example.com/admin?prmn=admin because of above rule.

I googled how to exclude admin folder from Rewrite then i got below

RewriteRule ^admin($|/) - [L]

When i use this then when i type http://example.com/admin then m getting error page that i defined in htaccess.

Please help. My Full Htaccess is as below

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^admin($|/) - [L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ / [L,R=301]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index
RewriteRule ^index\.php$ / [L,R=301]

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

 # remove .php from URL
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L] 

# restrict .php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /[^\ ]+\.php($|\ )
RewriteRule \.php$ / [F,L]

# remove .html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)\.html$ /$1 [L,R=301] 

RewriteRule ^([^/.]+)/?$ /blogdetail?prmn=$1 [L]

ErrorDocument 404 /error-page
ErrorDocument 403 /error-page
ErrorDocument 500 /error-page
1
What if you change the order of the statements in your configuration files? - G. Cito
Can you show full .htaccess in question - anubhava
my Htaccess has order as RewriteEngine On #RewriteRule ^admin($|/) - [L] RewriteRule ^([^/.]+)/?$ /blogdetail?prmn=$1 [L] .. So how u want to the chnage the order - Gags
@ Anubhava,, added htaccess in question - Gags
No Anubhava... admin do not have .htaccess - Gags

1 Answers

1
votes

I suppose there is an other rule that does something with /admin, but because you are using that second rule it will never reach that rule. Use a condition to exclude anything starting with admin instead. Also please note that the rule would rewrite it to /blogdetail?prmn=admin, so somewhere something is rewritten more.

RewriteCond %{REQUEST_URI} !^/(admin|blogdetail)
RewriteRule ^([^/.]+)/?$ /blogdetail?prmn=$1 [L]