I want to redirect my old url:
http://www.example.com/oldurl/name-%20(page.php?a=34
to this url:
http://www.example.com/newurl/
Most questions about redirecting URL’s are answering parts of my question like how to use "%20". But I don’t know how to use this all at once.
You can use this rule in root .htaccess:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^a=34$ [NC]
RewriteRule "^oldurl/name-(?:[ \s]|\x20)\(page\.php$" /newurl/? [L,NC,R=301]
Related
Sigh...
I tried constructing some rewrite rules based on the following Stack Overflow questions:
Question 1
Question 2
My .htaccess currently looks like this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(en|fr|es|de)/
RewriteRule ^(.*)$ /en/$1 [R,L]
RewriteRule ^(en|fr|es|de)/(.*)$ $2?locale=$1 [L]
and I've tried all sorts of variations (including the exact answers given in the questions).
As it stands my URL is redirecting to:
/en/?locale=en
When I look at the root with what looks like an infinite redirect loop in Firefox ('The page isn't redirecting properly').
As you've probably guessed I want it to rewrite to /en/ on the root and for it to look like that in the browser. But I want the real url to be /?locale=en. There is an index.php there on the root. Maybe I need another rule to take that into account?
I don't know, I'm really tired and exasperated and .htaccess has always been my downfall. Any insight appreciated.
You need to make sure there's no locale query string in your first rule:
RewriteCond %{QUERY_STRING} !locale=
RewriteCond %{REQUEST_URI} !^/(en|fr|es|de)/
RewriteRule ^(.*)$ /en/$1 [R,L]
Or you can try:
RewriteCond %{THE_REQUEST} \ /+(?!(en|fr|es|de)/).*
RewriteRule ^(.*)$ /en/$1 [R,L]
I'm running a wordpress installation and want to move specific feeds off-site. I've already got most of the technology down, but here's the problem. I want the following URL:
http://www.csicon.net/g/feed
to redirect to
http://feed.mesr.it/g
But if the URL comes in like this:
http://www.csicon.net/g/feed?noRedirect
I don't want it to redirect but load the original. Any thoughts?
The .htaccess file on http://www.csicon.net/ would contain:
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^\/g\/feed$ http://feed.mesr.it/g [L,R=301]
Note: It has not been tested, but you get the idea.
Later Edit: Also, this can be done in PHP.
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)csicon\.net$ [NC]
RewriteCond %{QUERY_STRING} !(^|&)noRedirect [NC]
RewriteRule ^([^/]+)/feed/?$ http://feed.mesr.it/$1 [L,NC,R=302]
I have read about htaccess redirect and rewrite on stackoverflow and on other sites and learned how to redirect simple pages and directories, but there are about 30 links remaining that I haven't been able to redirect. The reason appears to be because they contain "?" in the link's URL. I've tried the solutions posted but I haven't been able to make enough sense of them to succeed.
These work:
Redirect /Corpfleet.php htp://www.marketyourcar.cm/wraps.php
Redirect /drivers.php htp://www.marketyourcar.cm/drivers.php
Redirect /galleries.php htp://www.marketyourcar.cm/galleries.php
These do NOT work:
Redirect /ad.php?View=FAQ htp://www.marketyourcar.cm/advertiser-faqs.php
Redirect /ad.php?View=gallery htp://www.marketyourcar.cm/galleries.php
Redirect /ad.php?View=Materials htp://www.marketyourcar.cm/products-services.php
Yes, I know that the URL above is htp and .cm - I had to break it in order to make this post with my low reputation level.
If anyone can help with this I'd appreciate it.
Thanks
If you want to redirect from like:
site.com/index.php?blabla=1&id=32
to
site.com/contact.html
then use:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} blabla=1&id=32
RewriteRule ^(.*)$ http://www.site.com/contact.html? [R=301,L]
</IfModule>
Redirect can't handle that. RewriteRule can. This should work.
RewriteEngine on
RewriteRule ^/ad\.php\?View\=FAQ$ http://www.marketyourcar.cm/advertiser-faqs.php [R=301,L]
RewriteRule ^/ad\.php\?View\=gallery$ http://www.marketyourcar.cm/galleries.php [R=301,L]
RewriteRule ^/ad\.php\?View\=Materials$ http://www.marketyourcar.cm/products-services.php [R=301,L]
Or try this:
RewriteEngine on
RewriteRule ^/ad.php?View=FAQ$ http://www.marketyourcar.cm/advertiser-faqs.php [R=301,L]
RewriteRule ^/ad.php?View=gallery$ http://www.marketyourcar.cm/galleries.php [R=301,L]
RewriteRule ^/ad.php?View=Materials$ http://www.marketyourcar.cm/products-services.php [R=301,L]
This might work:
Example:
RewriteEngine On
RewriteRule ^/ad.php?View=FAQ$ http://www.marketyourcar.cm/advertiser-faqs.php? [R=301,L]
Add a trailing ? to the substitution URL to remove the incoming query.
Is it possible to redirect based on an url that would be as:
www.url.com/stuff.php
But not redirect if the url contained any characters after the php, as such:
www.url.com/stuff.php?variables=values&othervariable=othervalue&etc=more
I have no clue how to wriite this either.
Thanks in advance!
Edit: basically I need the redirect to happen to www.url2.com only if www.url.com ends with .php, but not if the .php is followed by variables.
try
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/site.com/?$ /site.com/cart.php [R=301,NC,L]
Try:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/?cart.php$ / [L,R=301]
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^stuff.php$ RELATIVE_OR_ABSOLUTE_URL_HERE [L]
Using htaccess how to turn this type of URL:
http://www.mysite.com/page.php?slug=hello-world
into this type:
http://www.mysite.com/page/hello-world
And not just this one url but all urls in the 1st format to the 2nd format.
If the second one is the URL you want people to see, use this:
RewriteRule ^page/(.*)$ /page.php?slug=$1
If it's the other way around:
RewriteRule ^page\.php?slug=(.*)$ /page/$1
EDIT: Also, make sure you have the following in your .htaccess before ANY RewriteRules:
RewriteEngine On
You may want to refer to here and this
Here is my thought to your solution:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^slug=[^/]+$ [NC]
RewriteRule ^page\.php$ http://www.mysite.com/page/$1? [R=301,L]