URL rewrite with an already rewritten URL - .htaccess

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]

Related

Is it possible to create a redirect rule from URL with slash to one without it?

I need to redirect all URLs with a slash at the end to the corresponding URL without it. For example I need to redirect this URL:
domain.com/category/subcategory/
to this URL:
domain.com/category/subcategory
Or this URL:
domain.com/category/
to this URL:
domain.com/category
How can I do it with a .htaccess redirect rule? Is it possible?
Thanks!
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

RewriteRule in htaccess does not work correct

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?

Redirect and rewrite

I'm not sure if it is possible but I want rewrite old URLs to new style and if someone will access the old URL i want to 301 redirect him to new URL style
OLD URL: /catalogue/category/some-category-page
NEW URL: /some-category-page/category
Also what I need is to pass REQUEST_URI to PHP script
I've got something like this but its not working (recursion):
RewriteEngine On
RewriteRule ^catalogue/category/(.+)$ /$1/category [R=301,L] # this is bad I know
RewriteRule ^(.+)/category?$ /catalogue/category/$1 [P]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(pdf|js|ico|gif|jpg|png|css|rar|zip|tar\.gz)$ index.php?modrewrited=%{REQUEST_URI} [QSA,L]
Thank you for help.
If your PHP script needs to read from $_SERVER['REQUEST_URI'], the you need to make sure mod_proxy is loaded. Except that causes a redirect loop. You need to have your first rule which redirects check the actual request variable. So instead of:
RewriteRule ^catalogue/category/(.+)$ /$1/category [R=301,L] # this is bad I know
you want:
RewriteCond %{THE_REQUEST} \ /+catalogue/category/([^\ \?]+)
RewriteRule ^ /%1/category [L,R=301]

.htaccess 301 redirect from old url to SEO friendly

I have link like this:
www.site.com/page.php?p=1
Need to rewrite it to friendly URLs in htaccess
RewriteRule ^home$ page.php?p=1
It works but now I have two active links with the same content.
Tried to add 301 redirect from old link to new but stuck in loop. Any ideas how to fix that?
Try matching against the actual request so that your rules won't loop:
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /page\.php\?p=1(&|\ |^)([^\ ]*)
RewriteRule ^page\.php$ /home?%3 [L,R=301]
# then your internal rewrite
RewriteRule ^home$ page.php?p=1
Remove the redirect on the page and handle it in the htaccess.
RewriteRule ^page\.php\?p=1$ /home [L,R=301]
This will redirect to /home and stop the redirect loop you have now.
another quick & dirty way to prevent looping in these situations i've found is to add a querystring and then check for its existence in the redirect.
RewriteCond %{QUERY_STRING} ^p=1
RewriteCond %{QUERY_STRING} !foo=bar
RewriteRule ^page\.php$ /home [NC,R=301,L]
RewriteRule ^home$ page.php?p=1&foo=bar [NC,L]
found on this site: http://answers.oreilly.com/topic/542-how-to-properly-redirect-for-maximum-seo/
Redirect 301 /page.php?p=1 www.yourwebsite.com/home?p=1 RewriteRule
^home?p=1$ /page.php?p=1

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