I'm trying URL re-writing for the first time and I have the following URLS which need rewriting:
http://domain.com/hotels/index.php?ct=new delhi
I want this as
http://domain.com/hotels/hotels-in-new delhi
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /hotels/index\.php\?ct=(\S+) [NC]
RewriteRule ^ /hotels/hotels-in-%1? [R=301,L,B] # Use QSD flag is Apache 2.4 or later
RewriteRule ^hotels-in-(.*)$ index.php?ct=$1 [L]
Related
i have requirement to redirect Apache on query base parameters for example
https://example.com/?ampostpreserve=01902018
I need to redirect to https://example.com .. I tried with
RewriteEngine On RewriteCond %{QUERY_STRING} ^ampostpreserv$
RewriteRule (.*) https://example.com [R=301,L]
but seem not working ..any solution
Thanks Hem
It seems like you just want to drop the query string? The QSD parameter does exactly that. The below version is for every called URL.
RewriteEngine On
RewriteCond %{QUERY_STRING} .+
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [QSD,L,R=301]
And this is the specific version for example.com and the above query string:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^ampostpreserve
RewriteRule .* https://example.com [QSD,L,R=301]
I am making a mini blog that could make it's url looks like this:
From: http://127.0.0.1/index.php?post=the-story-of-us
To: http://127.0.0.1/view/the-story-of-us
I have tried this but i'm getting 404 not found.
RewriteEngine on
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /index\.php\?post=([^&]+)
RewriteRule ^ /view/%2/? [L,R=301]
Your current rule only handles the case: Redirect old url to new url.
(By the way, +1 for using THE_REQUEST to avoid a redirect loop)
You also need to handle the case: Rewrite (internally) new url to old url.
Here is how your htaccess should look like
RewriteEngine On
# Redirect /index.php?post=XXX to /view/XXX
RewriteCond %{THE_REQUEST} \s/index\.php\?post=([^&\s]+)\s [NC]
RewriteRule ^ /view/%1? [L,R=301]
# Internally rewrite back /view/XXX to /index.php?post=XXX
RewriteRule ^view/([^/]+)$ /index.php?post=$1 [L]
I do not udnerstand your RewriteCondition, but the RewriteRule should look like this:
RewriteEngine on
RewriteBase /
RewriteRule ^view/(.*)/? ./index.php?post=$1 [L,R=301]
Via .htaccess, I would like to create an automatic 301 from an old URL to a new url:
An example old url is: http://www.example.com/test.html?s=2&ss=3
I would like that to be automatically redirected to: http://www.example.com/test.html
If you want to match this specific URL and query parameters then you can use this rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^s=2&ss=3^ [NC]
RewriteRule ^test\.html$ %{REQUEST_URI}? [L,R=302]
If you want to use this query string with any URI then use:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^s=2&ss=3^ [NC]
RewriteRule ^ %{REQUEST_URI}? [L,R=302]
? after %{REQUEST_URI} is needed to strip off any query string.
Here is my Problem
I have 10 URLS on a website A
I want to redirect 2 URLS (out of 10) from Website A to Website B via .htaccess
I want that 4 URLS from the list should never be redirected to anywhere
I want that remaining 4 URLS should be redirected to Website C
And Anyother URL from website A should redirect to Website D
Can any body help ?
Redirect /percussion/21021-crossing-grip-extensions http://myblog.tumblr.com/thisURL
Redirect /percussion/21045-indoor-percussion-circuits http://myblog.tumblr.com/thisURL
Redirect /percussion/21047-26-standard-rudiments-on-social-media http://myblog.tumblr.com/thisURL
RewriteCond %{REQUEST_URI} !^/wind-instruments/38250-hd200-excerpt-video
RewriteCond %{REQUEST_URI} !^/namm-2015-products/49480-gc1ta
RewriteCond %{REQUEST_URI} !^/namm-2015-products/49485-u1ta-2015
RewriteCond %{REQUEST_URI} !^/namm-2015-products/49486-a6r-a-series-2015
RewriteRule ^(.+)$ http://www.codephun.com/$1 [R=301]
You have a huge .htaccess file. I will provide few tips that you can use to fix your problem.
Don't use Redirect directive, just have your rules using RewriteRule itself.
Use THE_REQUEST variable instead of REQUEST_URI as THE_REQUEST variable that represents original request received by Apache from your browser and it doesn't get overwritten after execution of some rewrite rules.
So for the snippet shown above use:
RewriteEngine On
RewriteRule ^percussion/21021-crossing-grip-extensions http://myblog.tumblr.com/thisURL [L,NC,R=302]
RewriteRule ^percussion/21045-indoor-percussion-circuits http://myblog.tumblr.com/thisURL [L,NC,R=302]
RewriteRule ^percussion/21047-26-standard-rudiments-on-social-media http://myblog.tumblr.com/thisURL [L,NC,R=302]
RewriteCond %{THE_REQUEST} !/wind-instruments/38250-hd200-excerpt-video
RewriteCond %{THE_REQUEST} !/namm-2015-products/49480-gc1ta
RewriteCond %{THE_REQUEST} !/namm-2015-products/49485-u1ta-2015
RewriteCond %{THE_REQUEST} !/namm-2015-products/49486-a6r-a-series-2015
RewriteRule ^(.+)$ http://www.codephun.com/$1 [R=301]
# Rest of the Joomla rules come here
I want to redirect users to my home page if they enter any URL not starting with 'en' or 'fr'. I've spent hours trying to make this work but this proves too tough for my fragile newbie brain. Currently, if I try to go to
http://mysite.com/fr/produits/
Firefox tells me that the redirect will never complete.
Here's what I want:
http://mysite.com/en/whatever/ ==> rewrite as /whatever/index.php?lang=en
http://mysite.com/fr/whatever/ ==> rewrite as /whatever/index.php?lang=fr
http://mysite.com/jp/whatever/ ==> 301 redirect to /fr/accueil/
http://mysite.com/whatever/ ==> 301 redirect to /fr/accueil/
Here's my current htaccess. See inline comments for details.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Require no www
RewriteCond %{HTTP_HOST} !^mysite\.com$ [NC]
RewriteRule ^(.*)$ http://mysite.com/$1 [R=301]
# Redirect from root to /fr/accueil/, the URL for the default home page
RewriteRule ^/$ http://mysite.com/fr/accueil/ [NC,R=302]
# Rewrite language path fragment (/fr or /en) as a parameter
RewriteRule ^fr/accueil/$ /accueil/index.php?lang=fr [QSA,NC]
RewriteRule ^en/home/$ /accueil/index.php?lang=en [QSA,NC]
RewriteRule ^fr/produits/$ /produits/index.php?lang=fr [QSA,NC]
RewriteRule ^en/products/$ /produits/index.php?lang=en [QSA,NC]
# I'm aware that the rules in this htaccess are re-examined each
# time a rewrite is issued. So the 'fr/accueil/' I'm redirecting to
# will itself be rewritten as /accueil/index.php?lang=fr. That is
# why I'm providing 3 conditions:
# If URI does not start with 'en' AND
# If URI does not start with 'fr' AND
# If QUERY_STRING is not exactly 'lang'
RewriteCond %{REQUEST_URI} !^en/.*$
RewriteCond %{REQUEST_URI} !^fr/.*$
RewriteCond %{QUERY_STRING} !^lang$
RewriteRule ^.*$ fr/accueil/ [NC,R=301]
Please put me out of my misery. Cheers!
try replacing the last line
RewriteRule ^.*$ fr/accueil/ [NC,R=301]
With
RewriteRule ^.*$ fr/accueil/ [NCL,R=301]