Mod_Rewrite assistance for a noob please - apache

I want to rewrite all URLs of the form:
http://www.site.com/push20/dir1/dir2/afile.html
to
http://www.site.com/dir1/dir2/afile.html
I.e. lose the push20 bit
I've tried with:
RewriteEngine On
RewriteRule ^push20/(.*) /$1 [R]
but its not happening.
Any suggestion?

Won't you need a leading / before push20?
i.e:
RewriteRule ^/push20/(.*) /$1 [R]

Unless I'm missing something, you can do this with a standard Redirect directive, something along these lines:
Redirect /push20 /
That should redirect everything under /push20 to the root of your site -- basically it strips out push20 and redirects.

Related

Rewrite Rule - need guidance

I need to do some redirecting to get some internal links to work but I'm having a complete block.
The url would be http://www.something.com/faqs/What_happens_if_I_move_home?
redirected to http://www.something.com/faqs/index/What_happens_if_I_move_home?
but it must look like the original url. I'm sure there is a simple answer but rewrite rules and regex are a mystery to me at times.
I did try RewriteRule ^faqs(/.*)?$ /faqs/index$1 [R,L,NC]
amongst many others!
try this:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/faqs/index
RewriteRule ^faqs/(.*) /faqs/index/$1 [L,NC]

Htaccess redirections in apache

I'm trying to perform the following permanent redirections in .htaccess file, but I can not make them work. Can you help me?
Thank you very much. Regards!
Redirects are these:
http://www.mapfre.com.pa/productos/#39 to https://www.mapfre.com.pa/seguros-pa/seguros/seguros-salud/
http://www.mapfre.com.pa/productos#36 to https://www.mapfre.com.pa/seguros-pa/seguros/seguros-auto/
http://www.mapfre.com.pa/?post_type=corporativo&p=21 to https://www.mapfre.com.pa/seguros-pa/sobre-mapfre-panama/historia/
There's no way to make server-side redirect for URLs with an anchor #.
The last one may be done by this rule:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^post_type=corporativo&p=21$
RewriteRule ^$ /seguros-pa/sobre-mapfre-panama/historia/ [R=301,L]

301 .htacess redirect issue

I'm making a website, (for examples sake it will be http://www.example.com).I am trying to make it redirect http://example.com/jquery/releasenotes to http://blog.jquery.com/?s=release+notesBy using this it put a / on the end, this stops it from working, since it searches for the / aswell. I tried using http://goo.gl and converted it to http://goo.gl/WdiItL Somehow this also fails to remove the / when in redirect. However if you simply go to http://goo.gl/WdiItL it works. My .htaccess file looks like this:
Redirect 301 /jquery/releasenotes http://goo.gl/WdiItL
I have no idea how to make it not have the / on the end.Any help would be hugely appreciated!
Use this RedirectMatch rule:
RedirectMatch 301 ^/jquery/releasenotes/?$ http://goo.gl/WdiItL
Make sure to clear your browser cache before testing this
I think you have to use mod_rewrite's %{QUERY_STRING}
for example:
RewriteCond %{HTTP_HOST} =example.com [NC]
RewriteCond %{QUERY_STRING} ^(par1=1&par2=2)
RewriteRule ^$ http://alt.example.com/?%1 [R=301,L]

htaccess redirect catchall

I need to redirect a directory, and all subdirectories and files in that directory, to the same location (root). So anyone who tries to visit /old, /old/folder, /old/other-folder/xy/page.php, or anywhere else within the 'old' folder, should be redirected to the root domain.
So far, I have this:
Redirect 301 ^/old/.*$ /
Is this the best way of doing it, or would it be better to use (.*) instead of .*? What is the difference between the two?
Or - should I use a RewriteRule instead of a Redirect like above? If so, why?
Thank you!
The Redirect directive doesn't use regular expressions. It connects 2 path nodes together, which isn't exactly what you want. You can try using the RedirectMatch directive instead:
RedirectMatch 301 ^/old/ /
You can try this
RewriteEngine On
RewriteBase /
RewriteRule ^old/?(.*) /$1 [R=301,NC,L]
If you just want to redirect every old page to homepage/root(I'm not sure exactly what you want) than you can replace last rewriterule with
RewriteRule ^old/.* / [R=301,NC,L]

Basic URL rewrite with mod_rewrite

I would like to rewrite the URL of one of my pages from
http://www.mydomain.com/some/application/page.html
to
http://www.mydomain.com/apply
I believe this code will work. But in 301 redirects, you often see [R=301,L] or some version of that appended to the end of the rewrite rule - is the code below the best way to perform the redirection and will Google understand it?
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /some/application/page.html?=$1 [L]
I think you want to do this:
The URL that your users see (even google):
http://www.mydomain.com/apply
to
http://www.mydomain.com/some/application/page.html
the internal(actual) URL.
then I would suggest you to go this:
RewriteEngine On
#condition to redirect
RewriteCond %{REQUEST_URI} ^/?apply/?$
RewriteRule ^/?apply/?$ /some/application/page.html [L]
The flag [L] ( Flag L docs ) signifies RewriteEngine to stop rewriting any rules further. This will not perform a permanent redirection.
You don't need a [R=301] flag here. 301 is for permanent redirection. Use the short URL everywhere.
To my knowledge, you will need [R=301,L]to do a redirect properly. Apache2 by default will use a 302 redirect so if it is a permanent redirect you should force R=301, as you noted. The documentation for RewriteRule is unclear if [L] alone will always perform a 301 redirect. Be safe, tell apache exactly what to do :-).