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
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]
Related
I feel this should be an easy fix but I'm struggling to get it done right.
I have the URL:
http://www.testing.com/toursgbr/my-post
http://www.testing.com/toursgbr/my-post-2
I need to rewrite the URL to:
http://www.testing.com/tours/gbr/my-post
http://www.testing.com/tours/gbr/my-post-2
I got as far as the following:
RewriteRule ^toursgbr/(.*) /tours\/gbr/$1 [L]
This is what's currently in the htaccess file:
RewriteEngine on
ErrorDocument 404 http://www.ausweb.com.au/web-hosting
AddHandler server-parsed html
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^seabreezepark\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.seabreezepark\.com\.au$
RewriteRule ^/?$ "http\:\/\/theseabreezepark\.com\.au\/" [R=301,L]
RewriteRule ^toursgbr/(.+)$ /tours/gbr/$1 [NC,L]
and got nowhere pretty fast. I just want to look for the word "toursgbr" and change it to "tours/gbr" in summary.
Put the Following code at root .htaccess file :
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} !\s/+tours/gbr/ [NC]
# the above line will exclude any request having tours/gbr/ from the follwoing rule.
RewriteRule ^toursgbr/(.*)$ tours/gbr/$1 [R=302,L,NE]
# the above line will change any requested url having toursgbr/ to be tours/gbr/ temporary
# and you can change it to permanent by changing [R=302,L,NE] to [R=301,L,NE]
# but check the code as it is first then change it
RewriteRule ^tours/gbr/(.*)$ toursgbr/$1 [L,NC]
# the above line will internally map any request having tours/gbr/ to its original path
Try :
RewriteRule ^toursgbr/(.+)$ /tours/gbr/$1 [NC,L]
Do not use the full url in rewrite target if you want to internally redirect /toursgbr/foo to /tours/gbr/foo without changing the url in browser.
Your corrected htaccess :
ErrorDocument 404 http://www.ausweb.com.au/web-hosting
AddHandler server-parsed html
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?seabreezepark\.com\.au$
RewriteRule ^/?$ http://theseabreezepark.com.au/ [L,R=301]
RewriteRule ^toursgbr/(.+)$ /tours/gbr/$1 [NC,L]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
I have a page on my website that is getting generated dynamically to list all outlets based on cityf parameter and below is rewrite rule to convert it into SEO friendly URL and it is working pretty well.
RewriteRule ^([^/.]+)/?$ /cityres?cityf=$1 [L]
I have a blog page on my website and .htaccess is as below to convert SEO Friendly URL (http://example.com/title-of-blog)
RewriteRule ^([^/.]+)/?$ /blogdetail?prmn=$1 [L]
Now the problem here i am facing that when someone visits blog page then the link http://example.com/title-of-blog instead of displaying blog detail on the page, displays my Error message that No outlets near title-of-blog.
I got the issue that Apache is not able to identify when to rewrite cityres page and when to rewrite blogdetail page.
Someone suggested that Make sure that each rule has a common prefix (e.g. /blog/page1 and /news/page2). but i did not get that.
Any suggestions here please?
EDIT:
Whole htaccess is as below
Options +FollowSymLinks
RewriteEngine On
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]
# remove .html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)\.html$ /$1 [L,R=301]
ErrorDocument 404 /error-page
ErrorDocument 403 /error-page
RewriteRule ^food-([^-]*)-([^-]*)\.html$ /pdetail?res_id=$1&location=$2 [L]
RewriteRule ^foodies-([^-]*)-([^-]*)$ /pdetail_new?res_id=$1&location=$2 [L]
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/?$ /pdetail_ne?location=$1&res_id=$2&name=$3 [L]
RewriteRule ^blog/([^/.]+)/?$ /blogdetail_fm?prmn=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !cityres
RewriteRule ^([^/.]+)/?$ /cityres?cityf=$1 [L]
Both your rules match the exact same pattern. Therefore, the first rule will always match and the second rule does nothing.
Looking at the first rule:
RewriteRule ^([^/.]+)/?$ /blogdetail?prmn=$1 [L]
This matches http://example.com/title-of-blog as well as http://example.com/city-name
When you look at it, you can tell which needs to be handled by blogdetail and which needs to be handled by cityres, but the regex ([^/.]+) sees them both as exactly the same, and matches both. Your regex doesn't know the difference, so whatever the first rule is, both URL's will get matched by it.
Like you said, someone suggested using a prefix. That way, the regex knows which is which:
RewriteRule ^city/([^/.]+)/?$ /cityres?cityf=$1 [L]
RewriteRule ^blog/([^/.]+)/?$ /blogdetail?prmn=$1 [L]
ANd your URLs will look like:
http://example.com/city/city-name
http://example.com/blog/title-of-blog
If you're really hung up about not adding prefixes, you can remove the second prefix:
RewriteRule ^city/([^/.]+)/?$ /cityres?cityf=$1 [L]
RewriteRule ^([^/.]+)/?$ /blogdetail?prmn=$1 [L]
So that you have:
http://example.com/city/city-name
http://example.com/title-of-blog
EDIT:
Your 500 server error is caused by the rules looping. You need to add a condition so that they won't keep matching:
RewriteRule ^blog/([^/.]+)/?$ /blogdetail?prmn=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !cityres
RewriteRule ^([^/.]+)/?$ /cityres?cityf=$1 [L]
I don't have much knowledge in .htaccess and I am struggling with regex concept in .htaccess.
I want same url concept as on facebook for user profile but dash(-), underscore(_), dot(.) this I want in url also currently my url rule is as follow:
RewriteRule ^([a-z,\_,A-Z,\_,\-,0-9.][!pagenotfound|home|abuse/*|user/*|start/*|login/*|account/*|message/*|find/*|cms/*|accountactivation/*|register/*]*)/?$ memberspersonalinfo.php?members=$1 [QSA]
This pattern have some error
but when in my browser domain.com/username is comming it's working fine but when url will be domain.com/test-test or test_test or test.test it redirects to `PAGE NOT FOUND PAGE
and in my .htaccess rule defined to follow that rule like abuse/* have dynamic id wherever I have used star (*) they are referencing dynamic value. When I will do rule like
RewriteRule ^([a-z,\_,A-Z,\_,\-,0-9.]*)/?$ memberspersonalinfo.php?members=$1 [QSA]
It's working fine but when I moveto home page then it calls memberspersonalinfo.php page it self.
I am trying to explain my Question again with htaccess script
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
DirectoryIndex index.html index.php
ErrorDocument 404 /pagenotfound
ErrorDocument 403 /pagenotfound
ErrorDocument 401 /slapme/pagenotfound
ErrorDocument 500 /pagenotfound
#index
RewriteRule ^index.html$ index.php [L]
RewriteRule ^index$ index.php [L]
RewriteRule ^home$ index.php [L]
#nopage
RewriteRule ^pagenotfound$ nopage.php [L]
#Regitration
RewriteRule ^register/createaccount$ userregistration.php [L]
#Regitration Confirmation
RewriteRule ^register/accountconfirmation$ registrationconfirm.php [L]
#Activation Regitration
RewriteRule ^accountactivation/([a-z,\_,A-Z,\_,\-,0-9]*)/([a-z,\_,A-Z,=,\_,\-,0-9]*)$ registrationactivation.php?UsercontactID=$1&AccountId=$2 [L]
#after login
RewriteRule ^user/main$ after_login.php [L]
#Payment Detail
RewriteRule ^user/myaccount$ useraccount.php [L]
#Logout
RewriteRule ^user/logout$ logoutuser.php [L]
#creategroup
RewriteRule ^start/creategroup$ http://domain.com/start/creategroup [L,R=301]
#Forgot Password
RewriteRule ^user/forgotpassword$ http://domain.com/user/forgotpassword [L,R=301]
#Login
RewriteRule ^login/userlogin$ http://domain.com/login/userlogin [L,R=301]
#Remove account
RewriteRule ^account/remove$ removeuseraccount.php [L]
#Send an email page
RewriteRule ^message/?$ contacttouser.php [L,QSA]
#Report any site user page
RewriteRule ^abuse/([0-9]*)/$ reportsiteuser.php?reportUserID=$1 [L,QSA]
#CMS FIND FRIENDS PAGE
RewriteRule ^find/friend$ http://domain.com/find/friend [L,R=301]
#CMS TERMS OF USE PAGE
RewriteRule ^cms/howitworks$ howitworks.php [L]
#CMS CREATE OWN SLAP PAGE
RewriteRule ^cms/createownslap$ createownslap.php [L]
#CMS BRAND OR PRODUCT PAGE
RewriteRule ^cms/brandorproduct$ brandorproduct.php [L]
#CMS APPS AND FEATURES PAGE
RewriteRule ^cms/appsandfeatures$ appsandfeatures.php [L]
this my full htaccess code everthing is working fine all rules are working but when i add
#group personal profile page page
RewriteCond %{REQUEST_URI} !/abuse(.*)
RewriteCond %{REQUEST_URI} !/user(.*)
RewriteCond %{REQUEST_URI} !/start(.*)
RewriteCond %{REQUEST_URI} !/login(.*)
RewriteCond %{REQUEST_URI} !/account(.*)
RewriteCond %{REQUEST_URI} !/message(.*)
RewriteCond %{REQUEST_URI} !/find(.*)
RewriteCond %{REQUEST_URI} !/cms(.*)
RewriteCond %{REQUEST_URI} !/accountactivation(.*)
RewriteCond %{REQUEST_URI} !/register(.*)
RewriteCond %{REQUEST_URI} !/social(.*)
RewriteCond %{REQUEST_URI} !/images(.*)
RewriteCond %{REQUEST_URI} !/css(.*)
RewriteCond %{REQUEST_URI} !/js(.*)
RewriteCond %{REQUEST_URI} !/userimages(.*)
RewriteRule ^([a-z,\_,A-Z,\_,\-,0-9.]+)/?$ memberspersonalinfo.php?members=$1 [QSA,L]
it always loads memberspersonalinfo.php
i have a site wich have a dynamic url for 3 pages only. and for that i dont go for php function. So I decided to go for .htaccess rewrite rules but I am not having any luck yet.
This is my actual url: /index.php?mode=service&inid=1
I want to rewrite it to this: /home-theater
I try it my self and with this code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mysite\.com.au$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com.au/$1 [L,R=301]
Options +FollowSymLinks
DirectoryIndex index.php
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.mysite.com.au/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^home-theater/?$ index.php?mode=service&inid=1 [L,NC,QSA]
I still can't get it to work.
Also I write index.php to www redirect before this code, so I guess if it cause any issue or not. index.php to www site redirects work perfectly but this is not working.
Use L flag like this:
RewriteRule ^home-theater/?$ index.php?mode=service&inid=1 [L,NC,QSA]
Remember this will not change the URL in the browser since this will internally forward request to your index.php.
Also if this doesn't work then provide your full .htaccess in your question.
Update: I have modified your .htaccess here, please try it out now after clearing your browser cache:
DirectoryIndex index.php
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.mysite\.com.au$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com.au/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^ http://www.mysite.com.au/ [R=301,L]
RewriteRule ^home-theater/?$ index.php?mode=service&inid=1 [L,NC,QSA]
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.php [L]
I have in my .htaccess file the following code:
Options +FollowSymLinks
RewriteEngine On
Redirect 301 /index.asp http://www.website.com/index.php
Redirect 301 /contact.asp http://www.website.com/contact.php
RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^(.*/)?index\.([a-zA-Z0-9]{3,4})$ /$1 [R=301,L]
ErrorDocument 404 error.php
RewriteRule ^sitemap.xml sitemap.php
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteRule (.*) seofile.php?word=%{REQUEST_URI}
Now,
for some reason, when I entry to contact.asp I'm getting
http://www.website.com/seofile.php?word=/contact.asp
how can I fix it?
Try using rewriterule instead of Redirect (I think rewrite rules are applied before redirect rules). So something like:
RewriteRule ^index.asp / [R=301,L]
RewriteRule ^contact.asp /contact.php [R=301,L]
PS. the first rule can be removed, as you already rewrite every index.xxx file.
Advice: try to separate things that don't belong to RewriteRules.
Try this code and please tell me if it works:
ErrorDocument 404 error.php
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(index|contact)\.asp $1.php [QSA,R=301,L]
RewriteRule ^sitemap\.xml$ sitemap.php [L]
RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^(.*/)?index\.([a-zA-Z0-9]{3,4})$ /$1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule (.*) - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) seofile.php?word=%{REQUEST_URI}