: How do I redirect a URL using rewrite in .htaccess that has a question mark and forward slash where page.html is the variable? Hello and thanks to all who contribute to this seemingly mind
Hello and thanks to all who contribute to this seemingly mind boggling puzzle. I apologize in advance if .htaccess questions belong on server fault.
So I have to move a domain to our hosting servers, this domain will be redirected to another existing website. We need to redirect the individual pages to their respective pages on the existing website for user friendliness and SEO purposes. The URL pattern of the website being redirected are:
domain.com/index.php?/Page.html
I have found a lot of information in regards to redirecting strings with question marks, but none seem to work and I believe it's because of the / after the ?.
The following is the last RewriteRule I've tried:
RewriteCond %{REQUEST_URI} ^/index.php$
RewriteCond %{QUERY_STRING} ^/(.*).html$
RewriteRule ^(.*)$ www.domain.com/index/%1.html [R=301,L]
If I go to domain.com/index.php?/News.html the RewriteRule above results in the following:
domain.com/index/News.html?/News.html
I've also previously tried a rewrite from Drupal's site dealing with their nodes queries, but edited for the site I'm working on:
RewriteCond %{QUERY_STRING} ^/(.+)$
RewriteRule ^(.*)$ www.domain.com/index.php?/%1 [R=301,L]
RewriteRule ^/*(.*)$ www.domain.com/index/ [R=301,L]
The above results in a redirect loop. If I can at least get the URL to rewrite to a path with no question marks, I could then do individual redirects for the pages of the site.
Any help in getting rid of the question mark in this situation would be extremely appreciated.
EDIT:
Ultimately, I will be redirecting from one website to another. The websites don't have the same naming conventions, so I imagine I'll use redirect 301 path new URL for the individual pages.
An example of the start to finish, I would need to redirect the following URL:
www.domain.com/index.php?/About.html
to:
www.newsite.com/about.html
Not all of the old site names will be the same as you see About.html matching about.html, there will be URLs with News.html going to /Blog-Folder/.
What I imagine would be most efficient is getting the /index.php?/Page.html redirected to a folder path on the initial website so that it is set up like:
domain.com/index.php?/About.html -> domain.com/index/About.html -> newsite.com/about.html
Feel free to ask for more clarification if needed, I greatly appreciate any and all help.
More posts by @Pierce454
2 Comments
Sorted by latest first Latest Oldest Best
This should work for files of any extension:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^/(.*..*)$
RewriteRule ^index.php$ www.newsite.com/%1? [L,R=301]
Or to redirect the entire path and file request:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^/(.*)(..*)$
RewriteRule ^index.php$ www.newsite.com/%1%2? [L,R=301]
You could try using a simple Apache Redirect, like this:
Redirect 301 /index.php?/About.html www.newsite.com/about.html
It doesn't use regular expressions, so shouldn't care about the question mark and is simple to use. The only downside is that you'll need one per page - but if the structure and names aren't the same/similar on the new site, you might have to do that anyway.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.