I am using following htaccess code in my project
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /apnaujjain
#redirect localhost/apnaujjain/page.php?page_id=1&album_id=1&action=contacts to localhost/apnaujjain/1/1/contacts.html
RewriteCond %{THE_REQUEST} \s/+.+?\.php\?page_id=([^\s&]+)&album_id=([^\s&]+)&action=([^\s&]+) [NC]
RewriteRule . %1/%2/%3.html? [R=301,L]
RewriteRule ^([^/]+)/([^/]+)/([^./]+)\.html$ page.php?page_id=$1&album_id=$2&action=$3 [NC,L,QSA]
#redirect localhost/apnaujjain/page.php?page_id=1&action=contacts to localhost/apnaujjain/1/contacts.html
RewriteCond %{THE_REQUEST} \s/+.+?\.php\?page_id=([^\s&]+)&action=([^\s&]+)\s [NC]
RewriteRule . %1/%2.html? [R=301,L]
RewriteRule ^([^/]+)/([^./]+)\.html$ page.php?page_id=$1&action=$2 [NC,L,QSA]
#redirect localhost/apnaujjain/contacts.php to localhost/apnaujjain/contacts.html
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php\s [NC]
RewriteRule !^admin/ /%1.html [NC,R=302,L,NE]
RewriteRule ^(.+?)\.html$ $1.php [L,NC]
#RewriteCond %{THE_REQUEST} \s/+(.+?)\.php\s [NC]
#RewriteRule ^ /%1.html [R=302,L,NE]
#RewriteRule ^(.+?)\.html$ $1.php [L,NC]
Now everything is working fine except one thing I have some webservice also that I am calling from webservice folder, url is
http://localhost/apnaujjain/webservice/gethomepagecontent1.php
Now the problem is due to htaccess my webservice stopped working, it redirecting to wrong page so its not working. I don't want to apply htaccess rule on webservice folder. Please help, thanks in advance.
Just below RewriteBase /apnaujjain line add this line:
RewriteEngine On
RewriteBase /apnaujjain/
# add everything for webservice/...
RewriteRule ^webservice(/.*)?$ - [L,NC]
# rest of your existing rules
Related
I needed to redirect my od domain to a new one. All paths are same on both domains except the front page, which needed to be redirected from www.mydomain.com to www.mydomain2.com/newpath. I googled and came up with this code which works. My question is if it is valid and if all pageranks will be transfered without problems. Thank you
RewriteEngine on
RewriteCond %{HTTP_HOST} domain\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://www.domain1.com/folder/ [L,R=301]
RewriteRule ^(.*)$ http://www.domain1.com/$1 [L,R=301]
Your code should work but it can be fine tuned a bit. Please consider this refactored code:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
Rewriterule ^$ http://www.domain1.com/folder/ [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^ http://www.domain1.com%{REQUEST_URI} [L,R=301]
Can sombody help me out with this, im trying to re direct a page using htaccess file but it keeps adding ?c=oldpage on to the end of the new url, example:
http://www.mydomain.co.uk/newpage.html?c=oldpage
i have tried some of the solutions posted here but no luck, here is my .htaccess file:
DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} PHPSESSID=.*$
RewriteRule (.*) http://www.mydomain.co.uk/$1? [R=301,L]
RewriteCond %{HTTP_HOST} ^mydomain.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.co.uk/$1 [R=301,L]
RewriteCond %{THE_REQUEST} /index\.php\ HTTP/
RewriteRule ^index\.php$ / [R=301,L]
RewriteEngine on
RewriteRule ^product/(.*).html$ product.php?p=$1 [L]
RewriteRule ^(.*)\.html$ category.php?c=$1 [L,NC]
Redirect 301 /oldpage.html http://www.mydomain.co.uk/newpage.html
ErrorDocument 404 /404.php
Thanks for any help.
This is mod_alias (the Redirect directive) and mod_rewrite not playing nicely with each other. Because both modules apply their directives on the same URI in the URL-file mapping pipeline, they don't know to ignore each other since neither directive knows what the other module is doing. Since you're targets overlap, both modules are applying their directives on the same URI and you get a mish-mashed result.
You need to stick with mod_rewrite in this case and move the redirect above the internal rewrites:
DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks
RewriteEngine on
# redirects
RewriteCond %{QUERY_STRING} PHPSESSID=.*$
RewriteRule (.*) http://www.mydomain.co.uk/$1? [R=301,L]
RewriteCond %{HTTP_HOST} ^mydomain.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.co.uk/$1 [R=301,L]
RewriteCond %{THE_REQUEST} /index\.php\ HTTP/
RewriteRule ^index\.php$ / [R=301,L]
RewriteRule ^oldpage.html$ http://www.mydomain.co.uk/newpage.html [R=301,L]
# internal rewrites
RewriteRule ^product/(.*).html$ product.php?p=$1 [L]
RewriteRule ^(.*)\.html$ category.php?c=$1 [L,NC]
ErrorDocument 404 /404.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^abc\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.abc\.net$
RewriteRule ^example\.html$ "http\:\/\/abc\.net\/example\/" [R=301,L]
RewriteOptions inherit
to a folder, or:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^abc\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.abc\.net$
RewriteRule ^example\.html$ "http\:\/\/abc\.net\/example\.html$" [R=301,L]
RewriteOptions inherit
Don't know much about it, but it's what i use, hope it helps.
I'm using rewrite rules for search engine optimized url's
In my root folder I have the following .htaccess file:
Options +FollowSymlinks RewriteEngine On RewriteCond %{http_host} ^elitegameservers.net [NC]
RewriteRule ^(.*)$ http://www.elitegameservers.net/$1 [R=301,L]
rewriteEngine on
rewriteBase /
rewriteCond %{HTTP_HOST} ^(.*)haloservers(.nl|.us|.net)$
rewriteRule ^(.*) http://www.haloservers.net/$1 [L,R=301]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?haloservers(.nl|.us|.net) [NC]
RewriteRule ^(.*)\.html$ http://www.elitegameservers.net/$1 [R=301,L]
In the sub directory(/controlpanel) I run WHMCS with the following .htaccess file:
RewriteEngine On
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^elitegameservers.net [NC]
RewriteRule ^(.*)$ http://www.elitegameservers.net/controlpanel/$1 [R=301,L]
RewriteEngine On
# Announcements
RewriteRule ^announcements/([0-9]+)/[a-z0-9_-]+\.html$ ./announcements.php?id=$1 [L,NC]
RewriteRule ^announcements$ ./announcements.php [L,NC]
# Downloads
RewriteRule ^downloads/([0-9]+)/([^/]*)$ ./downloads.php?action=displaycat&catid=$1 [L,NC]
RewriteRule ^downloads$ ./downloads.php [L,NC]
# Knowledgebase
RewriteRule ^knowledgebase/([0-9]+)/[a-z0-9_-]+\.html$ ./knowledgebase.php?action=displayarticle&id=$1 [L,NC]
RewriteRule ^knowledgebase/([0-9]+)/([^/]*)$ ./knowledgebase.php?action=displaycat&catid=$1 [L,NC]
RewriteRule ^knowledgebase$ ./knowledgebase.php [L,NC]
I noticed that knowledgeable SEO optimization in WHMCS doesn't seem to work properly and it seems to be caused by the .htaccess code in my root directory.
Because of that I want the controlpanel sub directory to be excluded from the code in the root directory.
Thanks for any help
You could try adding a condition to the rules in your root directory to exclude requests starting with controlpanel:
RewriteCond %{REQUEST_URI} !^/controlpanel
rewriteCond %{HTTP_HOST} ^(.*)haloservers(.nl|.us|.net)$
rewriteRule ^(.*) http://www.haloservers.net/$1 [L,R=301]
RewriteCond %{REQUEST_URI} !^/controlpanel
RewriteCond %{HTTP_HOST} ^(www\.)?haloservers(.nl|.us|.net) [NC]
RewriteRule ^(.*)\.html$ http://www.elitegameservers.net/$1 [R=301,L]
I have the following .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain.com
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^mykeyword$ news.php [L,QSA,NC]
However, when I open the news.php, the url is still the same, that is www.mydomain.com/news.php instead of www.mydomain.com/mykeyword
I make the following test:
RewriteEngine on
RewriteRule ^test\.html$ test.php [L]
I upload 2 files on my server, test.html and test.php and after I type www.mydomain.com/test.html, my php page was displayed, so that mean that I have no problem with my settings. What on earth I am doing wrong???
Any help will be deeply appreciated.
Regards,Zoran
Change your .htaccess to this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(mydomain\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+news\.php [NC]
RewriteRule ^ mykeyword [R=301,L]
RewriteRule ^mykeyword/?$ news.php [L,NC]
The rewrite rule translates from the URL supplied by the user to the URL seen by the server. Try browsing to www.mydomain.com/mykeyword - you should see the page news.php.
I try to redirect http://mydomain.com to http://www.mydomain.com
I add this to my htaccess file, but it not work :
RewriteCond %{HTTP_HOST} ^mydomain\.fr [NC]
RewriteRule ^(.*)$ http://www.mydomain.fr/$1 [L,R=301]
This is the complete file :
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain\.fr [NC]
RewriteRule ^(.*)$ http://www.mydomain.fr/$1 [L,R=301]
# uncomment the following line, if you are having trouble
# getting no_script_name to work
#RewriteBase /
# we skip all files with .something
#RewriteCond %{REQUEST_URI} \..+$
#RewriteCond %{REQUEST_URI} !\.html$
#RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Try:
RewriteCond %{HTTP_HOST} !^www.mydomain.fr [NC]
RewriteRule ^(.*)$ http://www.mydomain.fr/$1 [L,R=301]
I'm using this on an existing site at the moment - seems to work fine here.
# Never keep domain name without subdomain
RewriteCond %{HTTP_HOST} ^mydomain\.fr$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.fr/$1 [R=301,L]