Mod rewrite apache - rewriting only base url - mod-rewrite

I'd like to rewrite
www.site.com/a/b/?param1=one&param2=two
in
www.site.com/c/d/e/?param1=one&param2=two.
Where www.site.com/a/b does not exists. I tried with
RewriteEngine on
Options +FollowSymLinks
RewriteRule ^a/b/(.*)$ www.site.com/c/d/e/$1 [QSA,L]
What's wrong with it?

Try this one:
RewriteEngine on
Options +FollowSymLinks
RewriteRule ^/a/b/(.*)$ /c/d/e/$1 [QSA,L]
There is no need for adding the incompleate domain. If you want that the users visit a second domain you have to add the R option and the protocol. For a redirect to a second domain try this:
RewriteRule ^/a/b/(.*)$ http://www.site.com/c/d/e/$1 [R,QSA,L]

Related

CodeIgniter and specific rewrite rule

On my CodeIgniter site, I would like to add a specific rewrite rule, so that this url
http://www.exemple.com/cache.manifest
would rewrite to
http://www.exemple.com/controller/manifest
(because Safari 7 seems to only accept .manifest files for ApplicationCache)
So I try to add this line to my htaccess
RewriteRule ^cache.manifest$ controller/manifest
I added it before the other rewrite rules :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^cache.manifest$ controller/manifest
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
But it returns a 404. If I change the line to
RewriteRule ^cache.manifest$ test.html
it works. So the first part on my rule is correct.
If I try to access directly to www.example.com/controller/manifest, it works to, so my url is correct.
I tried also
RewriteRule ^cache.manifest$ index.php/controller/manifest [L]
But it doesn't work either…
Any clue ?
Thanks a lot
I tried some tests on my local server and I think the following might work:
RewriteRule ^cache.manifest$ /index.php/controller/manifest [R,L]
I am not entirely sure if you need the leading "/" or "/index.php", so you
may need to experiment.
You need the [R] flag to force a redirect. In this situation, you want Apache
to look for the string cache.manifest in the URL, and then go to the CI page
controller/manifest.
It appears that you need to explicitly set the redirect.
Please let me know if this works. Good luck!

mod Rewrite : Hide php extension & replace variable name by slash

Need help, It is basic Mod-Rewrite. But i am confused
My current URL:
http://example.com/category.php?fn=accounting-tax
Want look like this:
http://example.com/category/accounting-tax
Only Apache Mod-Rewrite, No PHP please
Update:
Is it possible without PHP?
Thank you
Add this to your .htaccess in your web root /
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} (^|&)fn=(.*)(&|$)
RewriteRule ^category\.php$ category/%2 [NC,L]
Assuming, you meant
/category.php?fn=accounting-tax should take you to /category/accounting-tax
without showing up on the address bar. If you want an external redirect use [R=301,NC,L] instead.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^category/([a-z0-9\-]+)/item/?$ /category.php?id=$1
</IfModule>

mod_rewrite one url string

Can somebody tell me how to get mod_rewrite to rename this:
our-work-section.php?id=3&title=something
to
our-work-section/something/3
Right now my .htaccess is in directory C:\workspace\www\brown, My vhost is setup for http://workspace/, So I did a RewriteBase below. I currently Have:
RewriteEngine On
RewriteBase /www/brown/
RewriteRule ^/our-work-section/?$ our-work-section.php?id=$1 [NC,L]
My error log isn't saying anything, and the page doesn't do anything. I've tried toggling slashes / here and there.
Try this one
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(our-work-section)/?$ /our-work-section.php?id=$1 [L]
EDIT
This one will work. I tested it
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(our-work-section)/([^/\.]+)/?$ /our-work-section.php?id=$1 [L]

htaccess redirect to subfolder with same path attached?

How can I go about redirecting my old URLs which would have been: http:// blah.com/some/post/name
to the new URLs which would be: http:// blah.com/new/some/post/name
Is this even possible?
I don't want to simply redirect any requests for the blah.com domain to blah.com/new
I want to make sure the subpath is still attached to the redirect
it should be possible.
Try to put this in your .htaccess file:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/some\/?
RewriteRule (.*) /new/$1 [R=301]
</IfModule>
Try it out and let me know - I haven't had time to test it very thoroughly.

rewrite url module in windows does not redirect

I have used rewrite url module but I am not able to redirect to the target page and
I am getting error as:
The requested URL /old.html was not found on this server.
Here is my code:
<IfModule mod_rewrite>
RewriteEngine On
RewriteRule ^old.html$ new.html [R]
</IfModule>
Is AllowOverride set to All in your httpd.conf? Like this:
AllowOverride All
Also, your .htaccess should inlcude the L modifier for the last rule, and if you really want to redirect permanently, R=301:
RewriteEngine On
RewriteRule ^old.html$ /new.html [R=301,L]
You need to escape the . in .html with a \
So its:
RewriteEngine on
RewriteRule ^old\.html$ new.html [R]
Try also setting the RewriteBase to / like so
RewriteBase /
I've also tried this code for
RewriteEngine On
RewriteBase /
RewriteRule ^old.html$ /new.html [R=301,L]
error as The requested URL /old.html was not found on this server.
How to check the load module in apache server?

Resources