Basically I need to do exactly what the title says.
I have a client site using the following url structures:
http://www.example.co.uk/index.php?/<folder>/<file>
http://www.example.co.uk/?/<folder>/<file>
I need to redirect index.php?/ to ?/
Cheers for your help!
This should work for you:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /index\.php\?/(.*)\ HTTP
RewriteRule ^ /?/%2 [R=301,L]
It should change index.php?/folder/file to ?/folder/file
Related
Part of my .htaccess code is as follows:
RewriteRule ^([A-Z]+)*$ nextlevels_state.php?state=$1 [L]
RewriteRule ^([A-Z]+)*/([0-9]+)$ nextlevels_state.php?state=$1&page=$2 [NC]
This basically redirects URL, example.com/XX to example.com/nextlevels_state.php?state=XX and example.com/XX/1 to example.com/nextlevels_state.php?state=XX&page=1 (internally).
Now, I would like to change the URL structure of the URL from example.com/XX to example.com/nextlevels/XX and example.com/XX/1 to example.com/nextlevels/XX/1
and I tried changing .htaccess to as follows:
RewriteRule ^nextlevels/([A-Z]+)*$ nextlevels_state.php?state=$1 [L]
RewriteRule ^nextlevels/([A-Z]+)*/([0-9]+)$ nextlevels_state.php?state=$1&page=$2 [NC]
However, as the site urls are already indexed in search engines, I would like to know a way to redirect all the traffic from example.com/XX to example.com/nextlevels/XX (externally) using .htaccess .
Please guide me in this regard. Thank you community :)
Could you please try following, written and tested with shown samples only(improving your already done attempts here). Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
##Rule for redirect to url example.com/nextlevels/XX.
RewriteRule ^([A-Z]+)$ nextlevels/$1 [R=301]
RewriteRule ^nextlevels/([A-Z]+)/?$ nextlevels_state.php?state=$1 [NC,L]
##Rule for redirect to url example.com/nextlevels/XX/1.
RewriteRule ^([A-Z]+)*/([0-9]+)$ nextlevels/$1/$2 [R=301]
RewriteRule ^nextlevels/([A-Z]+)*/([0-9]+)$ nextlevels_state.php?state=$1&page=$2 [NC,L]
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]
I've created a website with a decent WordPress theme and framework about events but there's some links to a pretty annoying page like this:
/?event-category=gigs
I would like to redirect any links to URLs like that simply to:
/gigs
I'm hopeless in Htaccess, can someone suggest the syntax please? I'd appreciate it.
You can use this rule just below RewriteEngine On line:
RewriteCond %{QUERY_STRING} (^|&)event-category=(gigs) [NC]
RewriteRule ^ /%1? [R=302,L,NE]
sorry for this simple question, however i still cant get my head round using .htaccess
I'm trying to convert:
search.php?s=dvd&page=1
to
/Search/dvd/page1.html
Thanks,
Jack
I think something like:
RewriteRule ^search/([A-Za-z]+)/page([0-9]+)\.html$ search.php?$1&page$2
Should do the trick.
Further reading here: http://www.webforgers.net/mod-rewrite/mod-rewrite-syntax.php
you must put your link "/Search/dvd/page1.html" in the page and with htaccess it will convert to the "search.php?s=dvd&page=1" . i hope it be usefull :)
sample correct htaccess code :
RewriteEngine On
RewriteRule Search/(\d+)/page?(\d+)\.html$ search.php?s=$1&page=$2 [NC,L]
If I understand the question OP wants to convert php to html redirection. Try this rule in your .htaccess file:
RewriteEngine on
Options +FollowSymlinks -MultiViews
# to match /search.php?s=dvd&page=1
RewriteCond %{QUERY_STRING} ^s=([^&]*)&page=(.*)$ [NC]
RewriteRule ^search\.php/?$ /Search/%1/page%2.html? [R,L,NC]
# to match /search.php?page=12&s=dvd
RewriteCond %{QUERY_STRING} ^page=([^&]*)&s=(.*)$ [NC]
RewriteRule ^search\.php/?$ /Search/%2/page%1.html? [R,L,NC]
R=301 will redirect with https status 301
L will make last rule
NC is for no case comparison
%1 and %2 are the query parameter values
I think you want make clean URI, so if user type url like this:
search/televisi/page4.html
it same as like search.php?s=dvd&page=1
Add this code:
RewriteEngine On
RewriteRule ^search/([a-z]+)/page([1-9]+).html$ search.php?s=$1&page=$2
I am using the following code to attempt to redirect a dynamic URL to a new dynamic URL, under the same domain:
RewriteRule ^products/item/^\d([^/]+) /product/$1/ [R=301,L]
I've tried these too:
RewriteRule ^products/item/[^\d]([^/]+) /product/$1/ [R=301,L]
RewriteRule ^products/item/[0-9]([^/]+) /product/$1/ [R=301,L]
But this was redirecting /products/item/342/ to /product/42/, I tested this on a larger number (e.g. 123456789) and it redirected to /product/23456789/.
It would appear that my rule is not picking up the firsts digit, can anyone help me resolve this?
I've also tried using [\d] instaled of [0-9], but this has the same problem.
Cheers!
Try
RewriteRule ^products/item/(\d[^/]+) /product/$1/ [R=301,L]
RewriteRule ^products/item/([0-9]+) /product/$1/ [R=301,L]