I have a huge number of urls similar to
http://example.com/index.php?cPath=371_1659_1660&main_page=products_categories
I need to be able to rewrite them so that they are simply
http://example.com/index.php?cPath=371_1659_1660
I've tried several times but I just end up with Error 500 and my site is dead.
I fixed it with
RewriteCond %{QUERY_STRING} ^(.)(^|&)main_page=products_categories(.)$
RewriteRule ^(.*)$ /$1?%1%3 [R=301,L]
Related
I spent some hours looking for an answer via google and on here and I can't seem to get this to work
This is my URL:
http://mysite.co.uk/joomla30/landing-page-register?&tmpl=component
I simply want the ?&tmple=component removed in the browser URL only as the query at the end needs to be there at the server end but the browser would show.
http://mysite.co.uk/joomla30/landing-page-register
I have tried about 20 ways of doing this but I cant seem to get it to work I currently have
RewriteEngine On
RewriteRule ^landing-page-register$ /joomla30/landing-page-register? &tmpl=component [L]
htaccess is enabled as I already use it change a few .php files and redirect incoming traffic from warez sites, I just cant get this to work.
Thanks, Paul.
Try:
RewriteEngine On
RewriteCond %{THE_REQUEST} /joomla30/landing-page-register\?\&tmpl=component
RewriteRule ^ /joomla30/landing-page-register? [L,R]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^landing-page-register$ /joomla30/landing-page-register?&tmpl=component [L]
I want to rewrite
mypage.com/country/country.php?country=something
to
mypage.com/country/something
in the address bar, using htaccess
I've tried many things and looked everywhere and the closest I've got is:
RewriteCond %{QUERY_STRING} country=([^\&]*)
RewriteRule ^country.php$ /country/%1? [R,L]
But this just produces a rewrite loop that alternates between the two links above and I don't understand why.
I want both
mypage.com/country.php?country=something
and
mypage.com/country/something
when entered, to show
mypage.com/country/something
in the address bar
Any help?
If you have a rewrite loop it suggests that besides that rule, you also have a rule that translates it back. You'll need the 'ugly' url to only trigger when it is an external request. The easiest way to do that is by matching %{THE_REQUEST}.
#Ugly to fancy url; should be R=301 when it works
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /country\.php\?country=([^\&]*)\ HTTP
RewriteRule ^country.php$ /country/%2? [R,L]
RewriteRule ^country/(.*)/?$ /country.php?country=$1 [L]
I am trying to redirect a link ONLY if it's www.domain to a subdomain admin.domain I have been looking around and I am thinking it's my syntax messing me up. I am not so great with .htaccess redirects and rewrites. Here is what I have used so far.
Example 1
RewriteCond %{HTTP_HOST} !^www.mydomain.com$
RedirectMatch 301 ^/wp-admin/?(.*)$ http://admin.mydomain.com/wp-admin/$1
Here is the second on I also have been trying.
RewriteCond %{HTTP_HOST} !^www.mydomain.com$
RewriteRule ^/wp-admin/(.*)$ http://admin.mydomain.com/wp-admin/$1 [QSA,L,R=301]
This is working off an amazon AWS cluster so the code needs to stop once it rewrites only with www. That is where the loop keeps happening.
Any help would be deeply appreciated!
I think you got it backwards, you want to redirect IF the host is www.mydomain.com, not when it ISN'T. So get rid of the !:
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [NC]
RewriteRule ^/?wp-admin/(.*)$ http://admin.mydomain.com/wp-admin/$1 [QSA,L,R=301]
Note that the first code block you have won't work at all. You're using a mod_rewrite condition with a mod_alias directive, they're completely independent of each other.
I'm currently using the following htaccess to remove .php extension from all files:-
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
DirectoryIndex start.php?
On my start.php page I have a GET form (action="start") for the user to select there country (start?Country=USA).
Is it possible to rewrite URLs only on the start page to show the URL as mysite.com/USA? (removing "start?Country=" but including the question mark at the end of the URL) or will this conflict with the DirectoryIndex rule?
I've tried lots of different code I've found online but none of it seems to do what I need (and usually results in internal server errors).
Cheers for any pointers =)
I would like to rewrite URL's with htaccess to better readable URL's and use the $_GET variable in PHP
I sometimes make use of a subdomain so it has to work with and without. Also are the variables not necessary in the url. I take a maximum of 3 variables in the URL
the URL sub.mydomain.com/page/a/1/b/2/c/3 should lead to sub.mydomain.com/page.php?a=1&b=2&c=3 and the url sub.mydomain.com/a/1/b/2/c/3 should lead to sub.mydomain.com/index.php?a=1&b=2&c=3 where $_GET['a'] = 1
I came up with this after searching and trying a lot
RewriteEngine on
RewriteRule ([^/]+)\.domain.com/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ $1.domain.com/$2.php?$3=$4&$5=$6&$7=$8 [QSA,NC]
RewriteRule ([^/]+)\.domain.com/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ $1.domain.com/index.php?$2=$3&$4=$5&$6=$7 [QSA,NC]
RewriteRule ([^/]+)\.domain.com/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ $1.domain.com/$2.php?$3=$4&$5=$6 [QSA,NC]
RewriteRule ([^/]+)\.domain.com/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ $1.domain.com/index.php?$2=$3&$4=$5 [QSA,NC]
RewriteRule ([^/]+)\.domain.com/([^/]+)/([^/]+)/([^/]+)$ $1.domain.com/$2.php?$3=$4 [QSA,NC]
RewriteRule ([^/]+)\.domain.com/([^/]+)/([^/]+)$ $1.domain.com/index.php?$2=$3 [QSA,NC]
RewriteRule ([^/]+)\.domain.com/([^/]+)$ $1.domain.com/$2.php [L,QSA,NC]
but what I get is an not found server error
I'm not that good at this so maybe I oversee something.
Also I would like it to work with and without a slash at the end
Should I make use of RewriteCond and/or set some options?
Thanks in advance.
When using RewriteRule, you don't include the domain name in the line. Also, make sure you turn on the RewriteEngine first. Like this:
RewriteEngine On
RewriteRule ^([^/]+)/([^/]+)$ index.php?$1=$2
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$ index.php?$1=$2&$3=$4
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ index.php?$1=$2&$3=$4&$5=$6
The first line will rewrite sub.mydomain.com/a/1 to sub.mydomain.com/page.php?a=1, the second rewrites sub.mydomain.com/a/1/b/2 to sub.mydomain.com/page.php?a=1&b=2, and so on.