I am trying to redirect the URL but its conflicting with the rewrite-rule, I am using this redirection Rule
Redirect 301 /antique-vintage-rugs/170-antique-oriental-rugs-carpets https://example.com/antique-vintage-rugs/170-antique-rugs
it took me to this link
https://example.com/antique-vintage-rugs/170-antique-rugs?action=clear&template=170-antique-oriental-rugs-carpets instead of this
https://example.com/antique-vintage-rugs/170-antique-rugs
My Rewrite URL is this
RewriteCond %{QUERY_STRING} (.*)
RewriteRule ^antique-vintage-rugs/(.+) results.php?action=clear&template=$1 [NC]
Is there any way I can get the desired output redirect link?
You need to only be using mod_rewrite here instead of mixing it with mod_alias (where the Redirect directive belongs). When you mix the two, both end up processing the same request.
So instead of Redirect, use:
RewriteRule ^antique-vintage-rugs/170-antique-oriental-rugs-carpets https://example.com/antique-vintage-rugs/170-antique-rugs [L,R=301]
but make sure it's before your other rules.
I had a somewhat similar problem. I was trying to add redirects from cpanel while I already had some rewrite rules written in my .htaccess file. The error I got was "No maching tag for "
What I ultimately did was that kept a copy of my existing rules and cleaned the .htaccess. Then went and added all the redirects that I needed from cpanel, and then at the end put back my own rewrite rules in the end of the file. That worked for me
Related
I want to do a redirection from one static page to another page. This is the URL that I want to be redirected from
http://www.appmonks.net/post.php/66/5-Open-Source-iOS-Libraries-For-App-Development./?id=66&title=5-Open-Source-iOS-Libraries-For-App-Development
to below url
http://www.appmonks.net/id/66/What-is-CodeIgniter-?/
I have added below code in .htaccess, but it seems to be not working.
Redirect 301 /post.php/66/5-Open-Source-iOS-Libraries-For-App-Development./?id=66&title=5-Open-Source-iOS-Libraries-For-App-Development http://www.appmonks.net/
Use the below rewrite rule
RewriteEngine on
RewriteCond %{QUERY_STRING} id=66&title=5-Open-Source-iOS-Libraries-For-App-Development
RewriteRule (.*) "http://www.appmonks.net/id/66/What-is-CodeIgniter-?/" [L,R=301,NE]
I have tested it in online htaccess testing tool
results of the above rule
The problem with the redirect rule is the ? mark character in the url due to which redirect and rewrite rule is not working.
Also do ensure that mod_rewrite is included.
try
header("Location: http://www.appmonks.net/id/66/What-is-CodeIgniter-?/");
just put this code before anything is output.
My site uses RewriteEngine to hide variables in the URI as follows:
RewriteRule ^([^/\.]+)/?/([^/\.]+)/?$ page.php?theme=$1&pg=$2 [L]
This works fine, but as we're relaunching, we've got a few 301 redirects to handle as well. I've added these below my rewrite rules, here's an example:
redirect 301 /about/about-the-site https://www.mywebsite.com/about-us
The problem is, that it's redirecting but adding extra crap to the url string:
https://www.mywebsite.com/?theme=about&pg=about-the-site
Any idea why this would be happening?
Don't mix mod_alias and mod_rewrite rules as these 2 modules execute at different stages. Keep everything in mod_rewrite itself:
RewriteEngine On
RewriteRule ^about/about-the-site/?$ https://www.mywebsite.com/about-us? [L,NC,R=301]
RewriteRule ^([^/.]+)/?/([^/.]+)/?$ page.php?theme=$1&pg=$2 [L,QSA]
Also note extra ? in the target URL to strip any pre-existing query string. Make sure clear browser cache while testing it.
I'm having a pretty hard time on .htaccess URL rewrites in PHP. I want to put a specific condition to it but it has not worked out yet.
I WANT TO WRITE A CONDITION TO REDIRECT EVERYTHING THAT HAS A "GO" IN ITS URL
RewriteCond %{QUERY_STRING} ^.*&go=([^?&]*)\??([^&]*)&*.*$
Redirect /alice1.html http://www.google.com'
the failed condition that i tried
FOR AN EXAMPLE IF SOMEBODY TYPES
'localhost/alice1.html' IT SHOULD NOT BE REDIRECTED TO google.com
BUT IF IT IS
'localhost//alice1.html?go=www.something_something.com'
THEN IT SHOULD BE REDIRECTED.
You can start from this base rule.
RewriteCond %{QUERY_STRING} \bgo=.+
RewriteRule . http://google.com? [L]
Then refine the checking of the go variable.
edit: note that this is just a template rule matching your input. On a production server it would be better to either set it as an external redirection (using [R=301, L] instead of just [L], assuming you want it permanent) or switch to an appropriate error page (403, 404...)
I want to change a single URL on mysite from sitename.com/test123.php to sitename.com/article-about-stuff. There are no variables to consider, just a one-off URL change. Is this possible with mod_rewrite and RewriteRule? I currently have:
RewriteEngine on
RewriteRule ^article-about-stuff$ /test123.php [L,QSA]
At the moment the user is redirected, but the url is changed to test123.php. I want to keep the url.
I would also like to be able to redirect any traffic to test123.php to /article-about-stuff
How can I simply write out the destination URL and link to it with the prettier URL?
add the following directive to your .htaccess (this will redirect request from test123 to article-about...)
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^test123\.php$ /article-about-stuff [NC,R=301,L]
Note: the first condition assure that no previous redirection is made (to prevent redirection loop)
The answer to your question is "yes, it's possible," but I'm not sure why you need mod_rewrite for such a simple redirect.
RedirectMatch ^test123\.php$ /test123.php
See When Not To Use Rewrite.
I need to somehow make one unique url redirect.
For instance:
http://www.mydomain.com/shop needs to redirect back to http://www.mydomain.com
BUT
http://www.mydomain.com/shop/tshirts etc still needs to function, I cant manage to get this to work. No matter what I attempt anything containing /shop/xxx redirects which I dont want it to.
Thanks in advance!
Try this. Write this in .htaccess file.
RewriteEngine on
RewriteCond %{REQUEST_URI} /shop
Rewriterule ^$ http://mydomain.com/test/ [L,R=301]
You need to enable MOD_REWRITE.
Place a .htaccess file in the root folder of your server and have it contain:
RewriteEngine On
RewriteRule ^(.*)shop/$ http://mydomain.com/ [R,L]
Hope it works for you!
Your redirection seems simple enough, so you can use redirect directive for this.
In your .htaccess file, add this redirect.
Redirect 301 /shop http://www.mydomain.com/
301: permanent
302: temp
303: seeother
410: gone
mod_alias needs to be enabled in config.