I try to rewrite my URLs from domain.tld/?country=XX&admin1=YY&city=ZZ to domain.tld/XX/YY/ZZ
I have tried
RewriteEngine on
RewriteRule ^([A-Za-z]{2,2})/(.*)/(.*)$ /?country=$1&admin1=$2&city=$3 [QSA]
Unfortunately it doesn't work. Have I missed something?
You can have these rules in your root .htaccess:
RewriteEngine on
RewriteCond %{THE_REQUEST} /\?country=([^\s&]+)&admin1=([^\s&]+)&city=([^\s&]+) [NC]
RewriteRule ^ /%1/%2/%3? [R=302,L,NE]
RewriteRule ^(\w+)/(\w+)/(\w+)/?$ /?country=$1&admin1=$2&city=$3 [QSA,L]
Related
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
I created an htaccess i want to rename all extension .php files to .html
i put
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} (.*)\.php
RewriteRule ^(.*)\.php $1.html [R=301,L]
RewriteCond %{THE_REQUEST} (.*)\.html
RewriteRule ^(.*)\.html $1.php [L]
and it work fine.
Now i want to rename nettoyage-detail-bureaux.php?id=21 to nettoyage-detail-bureaux-21.html
so i add
RewriteRule ^nettoyage-detail-bureaux-([0-9]+)\.html$ nettoyage-detail-bureaux.html?id=$1 [L]
it doesn't work.
Any idea ?
I think you might have a typo at the end where you have .html?id=$1 it should be .php?id=$1
So try this.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^nettoyage-detail-bureaux-([0-9]+)\.html$ nettoyage-detail-bureaux.php?id=$1 [L]
RewriteCond %{THE_REQUEST} (.*)\.php
RewriteRule ^(.*)\.php $1.html [R=301,L]
RewriteCond %{THE_REQUEST} (.*)\.html
RewriteRule ^(.*)\.html $1.php [L]
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 need rewrite this url http://adresa.com/article.php?act=view&id=1113 to http://adresa.com/view/1113
I make it with mod_rewrite in .htaccess but it doesn't work.
RewriteBase /
RewriteCond %{QUERY_STRING} ^act=([^&]+)$
RewriteRule ^article\.php$ %1.html? [R=301,L,NE]
RewriteRule ^([^/]+)\.html article.php?rw=1&act=$1 [L,QSA]
RewriteRule ^([^/]+)/{1}([^/.]+)\.html article.php?rw=1&act=$1&id=$2 [L,QSA]
Can somebody help me please?
Here's the solution (with proper line-separation to avoid confusion (RewriteCond is valid for only one following RewriteRule, so put a blank line after to avoid confusion)):
RewriteBase /
RewriteRule /view/([0-9+])$ /article.php?act=view&id=$1 [QSA,L]
RewriteCond %{QUERY_STRING} ^act=([^&]+)$
RewriteRule ^article\.php$ %1.html? [R=301,L,NE]
RewriteRule ^([^/]+)\.html article.php?rw=1&act=$1 [L,QSA]
RewriteRule ^([^/]+)/{1}([^/.]+)\.html article.php?rw=1&act=$1&id=$2 [L,QSA]
I'm trying to redirect a user to /hd/142 if they don't have /hd/ in the URL. I've tried so many options and most of them just redirected me over and over again. Here is the current .htaccess that I have setup.
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js)
RewriteRule ^hd/(.*)$ /index.php/$1 [L]
RewriteRule ^(images|css|js)/(.*) /applicationFiles/$1/$2 [L]
Thanks
RewriteEngine on
RewriteBase /
#if url does not have hd in it
RewriteCond %{REQUEST_URI} !^/hd/ [NC]
#redirect to hd
RewriteRule ^ /hd/142 [L,R=301]
#existing rules
RewriteCond $1 !^(index\.php|images|css|js) [NC]
RewriteRule ^hd/(.*)$ /index.php/$1 [L,NC]
RewriteRule ^(images|css|js)/(.*) /applicationFiles/$1/$2 [L]
A simple solution would be to use routes.php in codeigniter:
$route['^(hd)'] = '/hd/142';
Read more under the Regular Expressions section here: http://codeigniter.com/user_guide/general/routing.html