I have URLs with two query parameters e.g. /skills/keywords/list.php?industry=retail&q=analyst and I'd like to redirect those URLs to /list-of-%2-skills-in-%1 .
I have tried the code below which looks at the query "industry" and "q" to build the destination URL: /list-of-%2-skills-in-%1
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^industry=(.*)&q=(.*)$ [NC]
RewriteRule ^skills/keywords/list\.php$ /list-of-%2-skills-in-%1? [L,R=301]
I'm expecting: /skills/keywords/list.php?industry=retail&q=analyst to redirect to /list-of-analyst-skills-in-retail which it does but I have a 404 content not found.
Can someone point me to the right direction please?
This is because the destination path /list-of-%2-skills-in-%1 doesn't exist on your server. You need to rewrite this path to the existent file /skills/keywords/list.php?industry=retail&q=analyst .
RewriteEngine On
RewriteBase /
#redirect /skills/keywords/list.php?industry=foo&q=bar
#to /list-of-bar-skills-in-foo
RewriteCond %{THE_REQUEST} /skills/keywords/list\.php\?industry=([^&]*)&q=([^\s]+) [NC]
RewriteRule ^skills/keywords/list\.php$ /list-of-%2-skills-in-%1? [L,R=301]
#rewrite new URL to the old one
RewriteRule ^list-of-([^-]+)-skills-in-([^-]+)/?$ /skills/keywords/list.php?industry=$1&q=$2 [NC,L]
Related
My actual and "desired" URL is (and works fine):
www.example.com/flower
The file is
www.example.com/indexmodelo.php?carpeta=flower
But I have the old URL to the same target ruled by "IP" instead "carpeta"
www.example.com/indexmodelo.php?IP=202
And I need that when you put:
www.example.com/indexmodelo.php?carpeta=flower
OR
www.example.com/indexmodelo.php?IP=202
Go to:
www.example.com/flower
In my .htaccess fil I have:
RewriteEngine on
Options -MultiViews
RewriteCond %{THE_REQUEST} \s/indexmodelo\.php\?carpeta=([0-9a-zA-Z_\-&=]+)\s [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteRule ^([0-9a-zA-Z_\-&=]+)$ /indexmodelo.php?carpeta=$1 [L]
Thanks for your help folks!
I am making a mini blog that could make it's url looks like this:
From: http://127.0.0.1/index.php?post=the-story-of-us
To: http://127.0.0.1/view/the-story-of-us
I have tried this but i'm getting 404 not found.
RewriteEngine on
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /index\.php\?post=([^&]+)
RewriteRule ^ /view/%2/? [L,R=301]
Your current rule only handles the case: Redirect old url to new url.
(By the way, +1 for using THE_REQUEST to avoid a redirect loop)
You also need to handle the case: Rewrite (internally) new url to old url.
Here is how your htaccess should look like
RewriteEngine On
# Redirect /index.php?post=XXX to /view/XXX
RewriteCond %{THE_REQUEST} \s/index\.php\?post=([^&\s]+)\s [NC]
RewriteRule ^ /view/%1? [L,R=301]
# Internally rewrite back /view/XXX to /index.php?post=XXX
RewriteRule ^view/([^/]+)$ /index.php?post=$1 [L]
I do not udnerstand your RewriteCondition, but the RewriteRule should look like this:
RewriteEngine on
RewriteBase /
RewriteRule ^view/(.*)/? ./index.php?post=$1 [L,R=301]
What I am trying to do:
Change
www.mysitename.com/pages/about
to
www.mysitename.com/about
What I have tried so far:
RewriteEngine on
RewriteRule ^(.*)$ pages/$1
but when I go onto my website and click the about section, the url is still www.**.com/pages/about. htaccess is enabled on my server, so that's not the problem.
What am I doing wrong?
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
# change URL in browser from /pages/about to /about
RewriteCond %{THE_REQUEST} \s/+pages/(\S*) [NC]
RewriteRule ^ /%1 [R=302,L,NE]
# internally forward /about to /pages/about
RewriteRule ^((?!pages/).+)$ pages/$1 [L,NC]
I would like to redirect the url http://intranet/trac/paradox/report/6 to http://cobra.woking/trac/paradox/report/6. trac is a subfolder and paradox is a subfolder. report/6 are params that need to be kept and may change.
In my apache doc root i have
#/opt/html/.htaccess
Redirect 301 / http://intranet/intranet
RewriteEngine On
RewriteRule ^trac/paradox/report/6$ http://cobra.woking/trac/paradox/report/6 [L,R]
I have tried the following which does not work
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^intranet$
RewriteRule (.*) http://cobra.woking/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^intranet$
RewriteRule (.*) http://cobra.woking/$1 [R=301,L]
URL i want to change is http://intranet/trac/paradox/ to http://cobra.woking/trac/paradox/. I have placed .htaccess in the /opt/html/trac/paradox/.htaccess
In the htaccess file of your intranet's document root, add this to the top of the file:
RewriteEngine On
RewriteRule ^trac/paradox/report/6$ http://cobra.woking/trac/paradox/report/6 [L,R]
I'm attempting to redirect some rewritten URL's but while the redirect is working, it is including the original parameter before the rewrite.
e.g. Redirect /used-cars.html http://www.odins.co.uk/our-cars.html
The rewritten URL is based upon the following structure:
http://www.domain.co.uk/pages/index.php?p=used-cars
However, what is happening is this:
http://www.domain.co.uk/our-cars.html?p=used-cars
The .htaccess file is as follows:
Options -Indexes
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^odins.co.uk [NC]
RewriteRule ^(.*)$ http://www.odins.co.uk/$1 [L,R=301]
RewriteRule ^([^/]*)\.html$ /pages/index.php?p=$1 [L]
RewriteRule ^news/([^/]*)$ /pages/news/index.php?n=$1 [L]
Redirect /used-cars.html http://www.domain.co.uk/our-cars.html
Any help would be appreciated.
Paul