I want to redirect www.example.com/ext_jobs/ to www.example.com/customer/tremoria/ext_jobs/
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^/ext_jobs/(.*)$ customer/tremoria/ext_jobs/$1 [L]
But my solution is not working. What's wrong?
You can use the rewritebase instead of the / in ^/ext_jobs/(.*)$
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^customer/tremoria/ext_jobs
RewriteRule ^ext_jobs/(.*)/?$ customer/tremoria/ext_jobs/$1 [L,NC,QSA]
Do not use mod-rewrite for simple things. You have simple solutions with mod-alias like Redirect, RedirectMatch and Alias.
In your case I would try a Redirect if you really need a Redirect. But in your sample you are only doing an internal redirect, transparent to the user browser.
So an Alias is maybe the solution
Alias ext_jobs/ customer/tremoria/ext_jobs/
Related
I need to redirect a few specific dynamic php pages to an external website domain. For example,
siteA.com/home/space.php?uid=357&do=thread&id=396
to
siteB.com
I put the following in my .htaccess but it didn't work.
Options +FollowSymlinks -MultiViews
RewriteEngine On
Redirect home/space.php?uid=357&do=thread&id=396 http://www.siteB.com
what's wrong with this? any suggestion is appreciated. thanks!
From this:
Redirect home/space.php?uid=357&do=thread&id=396 http://www.siteB.com
to this:
RewriteRule ^[home/space.php?uid=357&do=thread&id=396]+$ http://www.siteB.com [R=301,L]
You need to use RewriteCond for matching query string:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteCond %{QUERY_STRING} ^uid=357&do=thread&id=396$ [NC]
RewriteRule ^home/space\.php$ http://www.siteB.com [L,NC,R=302]
I'm currently using a CMS that rewrites all URLs and currently I have a URL like this:
http://www.domain.com/folder/?user=user1
I'm looking to have that rewrite to: index.php?r=search&term=$1
Would something like this work?
RewriteRule ^/?user=(.*) index.php?r=search&term=$1 [L]
Seems to be giving me trouble. Any suggestions?
The query string is not part of the URI-path test it in the rule. It is at QUERY_STRING variable.
You may try this:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} user=([^/]+)/? [NC]
RewriteRule ^folder/? /index.php?r=search&term=%1 [L,NC]
try ( not tested)
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^folder1/?user=(.*)$ index.php?r=search&term=$1 [R=301,L]
RewriteRule new/$ /search.php?category=1
RewriteRule new/\?(.+)$ /search.php?category=1&$1
I'm trying to do something like this, if the following address link is accessed,
http://onlineshop.com/new/
http://onlineshop.com/new/?price_max=30
then it will open this link,
http://onlineshop.com/new/search.php?category=1
http://onlineshop.com/new/search.php?category=1&price_max=30
Unfortunately it is not working this way.
A RewriteRule won't naturally catch query string parameters, you must use this kind of .htaccess :
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^new/$ /search.php?category=1&%1
You can just simply redirect from /new to /search.php with QSA flag and Apache will append the existing query string. Something like this will work for you:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^new/?$ /search.php?category=1 [L,QSA,NC]
I got a website script where it's very difficult to change page slugs.
So I thought I can do this with .htaccess.
I got my page url like - www.mysite.com/submit
So can I change this with .htaccess to www.mysite.com/create ???
Thank you!
Something as simple as your example can be easily done by .htaccess. Use this code in .htaccess under DOCUMENT_ROOT:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^submit/?$ create [L,NC,R]
RewriteRule ^create\$ /submit [L]
or
RewriteRule ^create$ /submit [L]
I'm trying to set up a rewrite that will redirect this URL:
/video-2011.php?video=150
to this:
/video/150/freeform-title-text-here/
I have the rewrite working using this line in my HTACCESS:
RewriteRule ^video/([0-9]+)/(.*)$ video-2011.php?video=$1 [L]
But as soon I add R=301 into the mix, it breaks. Any ideas?
Here's the full HTACCESS when it breaks:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^video/([0-9]+)/(.*)$ video-2011.php?video=$1 [R=301,L]
Any help is greatly appreciated, thanks!
I think you might be missing a line from your .Htaccess.
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^video/([0-9]+)/([a-z0-9-_]+)$ video-2011.php?video=$1 [L]
#New
RewriteCond %{REQUEST_URI} !^/video/([0-9]+)/([a-z0-9-_]+)/?$
RewriteCond %{QUERY_STRING} ^video=([0-9]+)&name=([a-z0-9-_]+)/?$
RewriteRule ^video-2011.php$ video/%1/%2/? [R=301,L]
I assuming you want to rewrite the url if it is:
/video/150/freeform-title-text-here/
And redirect the url if it is:
/video-2011.php?video=150
to:
/video/150/freeform-title-text-here/
So this way it keeps the urls looking pretty and tidy.
Please correct me if I am wrong.
Edit
I've added in a RewriteCond to stop the second rewrite happening.
As the first rule will obviously rewrite:
/video/150/freeform-title-text-here/
Which means the query string you don't see:
/video-2011.php?video=150
Would of made the second rule happen too.
Can you try:
RewriteRule ^video/([0-9]+)/ /video-2011.php?video=$1 [R=301,L,NC,QSA]
And yes it will redirect /video/150/foo to /video.php?video=150 not the other way around as you've stated in your question.