RewriteRule in htaccess does not work correct - .htaccess

I have to rewrite old URLs like this:
Old URL:
http://www.domain.de/index.php?id=189&ext[stars]=PvVYdx58CfBpEIcUsdDvuE4fsvnwHw
New URL:
http://www.domain.de/sub1/sub2/stars/PvVYdx58CfBpEIcUsdDvuE4fsvnwHw
So I built following rule in my .htaccess file:
RewriteCond %{QUERY_STRING} ^id=([0-9]+)&ext\[stars\]=([A-Za-z0-9-]+)$
RewriteRule ^(.*)$ http://www.domain.de/sub1/sub2/stars/%2? [L,R=301]
but it does not work, the redirect happens to http://www.domain.de/sub1/sub2 without adding the parameter.
Any hints how to get this working?

Related

.htaccess mod_rewrite with GET parameters does not redirect

I want to rewrite URLs like:
product_reviews.php?products_id=3
to
haendlerbewertung::_::3.html
In my .htacces I defined:
RewriteRule ^haendlerbewertung::_::([^/]*)\.html$ product_reviews.php?products_id=$1 [L]
This rewrite rule works as it should, but there is no redirection from old to new URL, so each site can be called with 2 different URLs. If I write [L,R=301] the new URL wil be redirected to the old, but that's wrong. The old URL should be redirected to new one. So what's wrong or missing?
You can use the following :
RewriteEngine on
#redirect old url to the new one
RewriteCond %{THE_REQUEST} /product_reviews.php\?products_id=([^\s]+) [NC]
RewriteRule ^.+$ /haendlerbewertung::_::%1.html? [NE,L,R]
# map new url to the old one
RewriteRule ^haendlerbewertung::_::([^/]*)\.html$ /product_reviews.php?products_id=$1 [L]

.htaccess rewrite rule with get params

I need to be able to rewrite http://example.com/staging/details/?postid=23 so that it becomes http://example.com/staging/grandhotelterduin
I am not sure how the .htaccess rule should be?
I have came up with something like this
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^grandhotelterduin/(.*)$ ./details/?postid=23 [L,NC]
I am not sure I am doing this correctly, can you plz help
I want it such that the http://example.com/staging/grandhotelterduin/ get redirected to http://example.com/staging/details/?postid=23 but the url that appears in the browser is `http://example.com/staging/grandhotelterduin
Use this:
RewriteEngine On
RewriteRule ^grandhotelterduin$ /staging/details/?postid=23 [L]
It will give you the following URL:
http://sheetz.nl/grandhotelterduin
EDIT:
RewriteCond %{THE_REQUEST} /staging/details/?postid=([0-9]+) [NC]
RewriteRule ^ /staging/grandhotelterduin [L,R]

url cleanup with .htaccess rewrite mode url cleanup

i have htaccess problem.
i want use htaccess rewrite mode for change this url:
http://somedomain.com/?id=https://play.google.com/store/apps/details?id=com.supercell.clashofclans
to this:
http://somedomain.com/?id=com.supercell.clashofclans
I've folowed some .htaccess tutorials but I couldn't. How can I make it work?
This should work for you:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=(.*)?id=(.*)
RewriteRule ^$ /?id=%2 [L,R=301]

URL rewrite with an already rewritten URL

I want to implement a redirect via .htaccess from the old URL:
http://derpiet.de/photos/ireland
to the URL:
http://derpiet.de/photos/alben/2013/07/ireland
The system in the background is koken (http://koken.me).
Is it possible?
So, this will work:
RewriteCond %{REQUEST_URI} ^/photos/ireland/$
RewriteRule .* alben/2013/05/ireland [L,R=301]

How to stop htaccess rewrite rule carrying over query string

I am setting up some redirects. I want to redirect the following URL:
/cms/index.php?cat_id=2
to the following URL:
/flash-chromatography
The rule I currently have is as follows:
RewriteCond %{QUERY_STRING} ^cat_id=2$ [NC]
RewriteRule ^cms/index\.php$ /flash-chromatography [L,R=301]
This rule is almost perfect apart from it redirect the URL to the following:
/flash-chromatography?cat_id=2
So you see my problem is it has kept the ?cat_id=2 part when I don't want it to.
How do I stop it keeping this bit?
Just add ? at the end of rewritten URL:
RewriteCond %{QUERY_STRING} ^cat_id=2$ [NC]
RewriteRule ^cms/index\.php$ /flash-chromatography? [L,R=301]

Resources