.htaccess redirect to new domain - .htaccess

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

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.

301 hidden Redirect with Parameter

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]

Complex htaccess subfolder 301-redirection

I have a little problem with htaccess redirection, I have an issue which i can't figure out.
www.old.com/sub should direct to: www.new.com/page/
BUT
all the subpages of www.old.com/sub (www.old.com/sub/1, www.old.com/sub/2), should redirect to www.new.com/category/1, www.new.com/category/2 etc. (insted of page)
But how?
What I tried (i assumed this should work, but it didn't):
RewriteEngine on
RewriteRule ^sub/$ http://www.new.com/page/ [R=301,L]
RewriteRule ^sub(/.*)?$ http://www.new.com/category/$1 [R=301,L]
note; it is part of a large list of redirections, so it should not affect other redirections in this htaccess file.
That work with:
RewriteEngine on
RewriteRule ^sub/?$ http://www.new.com/page/ [R=301,L]
RewriteRule ^sub/(\d+)/?$ http://www.new.com/category/$1 [R=301,L]
You can change (\d+) to (.+) if you do not use numbers only after sub/

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

.htaccess Rewrite /... to /?url=

I am trying to rewrite URLs like this: http://url.maxk.me/abc to http://url.maxk.me/?url=abc, but for some reason it is not working.
Please can you tell me what I am doing wrong?
RewriteEngine on
RewriteRule ^(?:.*)url.maxk\.me/(.*)/?$ url.maxk.me?url=$1
You shouldn't include the domain in the RewriteRule target resource.
It should look like the following if you want the "?url" part to be visible to the user:
RewriteRule ^(.*)$ http://url.maxk.me/?url=$1
Otherwise, if you don't want the user to see "?url", it should look like this:
RewriteRule ^(.*)$ ?url=$1
try using this:
RewriteRule ^(.*)$ ?url=$1

Resources