301 hidden Redirect with Parameter - .htaccess

A image gallery moves to a new place.
Old:
album_showpage.php?pic_id=1
New:
/image/gallery/image_page.php?image_id=1
The new file
image_page.php
make a 301 redirect to something like this:
/category-1/image-1.html
I need a hidden redirect from old to new.
I tried:
RewriteRule ^album_showpage.php?pic_id=([0-9]+) /image/gallery/image_page.php?image_id=$1 [L]
But album_showpage.php gives me always a 404.
Thank you

Use that:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^pic_id=(\d+)$ [NC]
RewriteRule ^album_showpage\.php$ /image/gallery/image_page.php?image_id=%1 [L]

Related

Problem with using Rewriterule in htaccess

With RewriteRule I've always cleaned my URLs as following:
RewriteRule ^page/(.*)$ page.php?urlkey=$1 [QSA]
My new host doesn't allow me to use Options +FollowSymLinks and therefore I cannot use the / anymore. So I've changed my RewriteRule to:
RewriteRule ^page-(.*)$ page.php?urlkey=$1 [QSA]
However, I need to redirect all my former URLs to the new version. I tried doing this using the following rule:
RewriteRule ^page/(.*)$ page-(.*)$ [R=301,L]
This is however not working. I've also tried to just make a Redirect in my .htaccess:
Redirect 301 https://www.example.com/page/urlkey https://www.example.com/page-urlkey
This is also not working.
EDIT
As requested the actual code below:
RewriteEngine on
RewriteRule ^citywalk-(.*)$ citywalk.php?urlkey=$1 [QSA]
RewriteRule ^citywalk/(.*)$ citywalk-(.*)$ [R=301,L]
For example the citywalk The Historical Centre has a urlkey the-historical-centre. The old url is citywalk/the-historical-centre.
To test this specific case and other technique:
Redirect 301 /citywalk/the-historical-centre https://example.com/citywalk-the-historical-centre
By visiting https://example.com/citywalk/the-historical-centre no redirecting takes place (the url stays the same in the browser) and no urlkey is found.

.htaccess redirect to new domain

Need to redirect on this format:
https://old.com/pages/1248/some-title
https://new.com/pages/1248/some-title
I have tray this code:
RewriteRule ^pages/(\d+)/[^/]+$ https://new.com/pages/$1/+[^/] [R=301,L]
but the rezult faill on the "some-title" and look like this:
https://new.com/pages/1248/%2B%5B%5E/%5D
Solvet
RewriteRule ^pages/(\d+)/(.*) https://new.com/pages/$1/$2 [R=301,L]
adding (.*) will work

Redirect Dynamic URL with questionmark and ampersand?

I have redirect dynamic URL's which I'd like to redirect (301).
Link type 1
OLD - /?mainPage=Contact
NEW - /Contact
Link type 2
OLD - /?mainPage=Shows&show=circus
NEW - /shows/circus
How to do this?
To achieve that URL, you can use the following rule in your .htaccess:
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /?mainPage=$1&show=$2 [L]
Make sure you clear your cache before you test this.
To redirect a URL using a query:
RewriteCond %{QUERY_STRING} mainPage=Optredens&show=petitcirque$
RewriteRule (.*) /shows/le-petit-cirque/? [R=301,L]

Query string need to be redirected using .Htaccess

I have a serious issue in .htaccess, I have a URL like:
http://www.abc.com/xyz.php?title=Video-Tutoring
I need the URL to look like this:
http://www.abc.com/Video-Tutoring
This should affect only the page xyz.php.
To internally-redirect http://www.abc.com/Video-Tutoring to http://www.abc.com/xyz.php?title=Video-Tutoring use this:
RewriteRule ^/?Video-Tutoring$ xyz.php?title=Video-Tutoring [L,QSA]
To internally-redirect http://www.abc.com/ANYTHING to http://www.abc.com/xyz.php?title=ANYTHING use this:
RewriteRule ^(.*)$ xyz.php?title=$1 [L,QSA]
To redirect the URL visible by the user from http://www.abc.com/Video-Tutoring to http://www.abc.com/xyz.php?title=Video-Tutoring use this:
RewriteRule ^/?Video-Tutoring$ xyz.php?title=Video-Tutoring [R=301,L]
To redirect the URL visible by the user from http://www.abc.com/ANYTHING to http://www.abc.com/xyz.php?title=ANYTHING use this:
RewriteRule ^(.*)$ xyz.php?title=$1 [R=301,L]
To redirect the URL visible by the user from http://www.abc.com/xyz.php?title=Video-Tutoring to http://www.abc.com/Video-Tutoring use this:
RewriteRule ^/?xyz\.php\?title=Video-Tutoring$ Video-Tutoring [R=301,L]
To redirect the URL visible by the user from http://www.abc.com/xyz.php?title=ANYTHING to http://www.abc.com/ANYTHING use this:
RewriteRule ^/?xyz\.php\?title=(.*)$ $1 [R=301,L]
I hope that helps!
By the way the above is to put in your .htaccess file after the line RewriteEngine On

301 Redirect with mod_rewrite

I have some SEO to do on my site.
I'd like that the page 'red-bags' point to the search page 'search.php?keyword=red bags'
In addittion I'd like that the old search page makes a 301 redir to the new red-bags.
RewriteBase /
RewriteRule ^red-bags /search\.php/keyword=red\sbags [NC,L]
RewriteCond %{QUERY_STRING} keyword=red\sbags
RewriteRule ^search.php http://www.mysite.com/red-bags [R=301,L]
The second rules not work. Please help.
Try changing the second rule to this:
RewriteCond %{QUERY_STRING} keyword=red%20bags
RewriteRule ^search.php http://www.mysite.com/red-bags? [R=301,L]
In the first line the space is changed to the urlencoded %20
The question mark at the end of red-bags strips off the query string, otherwise it would have automatically been appended to the new url.

Resources