I have converted my asp site to php recently.
URLs remained the same, but obviously mysite.com//.asp pages became mysite.com//.php
I used this .htaccess entry to redirect (and it works perfectly):
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.asp$ $1.php [R=301, L]
My problem is, that I had to change some of the old URLs, so the above rule doesn't function properly.
Is it possible to add additional rules to .htacces, that overwrite the above global rule?
Like
Redirect 301 /path/page.asp mysite.com/path/page_new.php
and if possible, where to put it?
Thank you.
Stick with mod_rewrite since you're already using it and not through mod_alias(Redirect) into the mix.
Just add the URL's you want redirect specifically before your catchall rule.
RewriteEngine on
RewriteBase /
RewriteRule ^specific\.asp$ /path/page_new.php [R=301,L]
RewriteRule ^specific2\.asp$ /path/page_new2.php [R=301,L]
RewriteRule ^(.*)\.asp$ $1.php [R=301, L]
Let me know how this works out.
Related
I'm trying to redirect a url but I can't seem to make it work for some reason. I'm trying to redirect my.domain.com/rss/abc/ to my.domain.com/rss/abc/?type=555
I've put this in my .htaccess
RewriteEngine On
# Redirects rss
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/rss/abc/?$ /rss/abc/?type=555 [R=301,L]
Any pointers ? This is on a old TYPO3 site. Anyway it could hijack the request before doing the redirect ?
I can only recommend to use some kind of online htaccess rewrite rule checker, for example https://htaccess.madewithlove.com/ (not the only one, and no real preferance or recommendation about others).
Your rewrite rule is wrong, it should be:
RewriteEngine On
# Redirects rss
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^rss/abc/?$ /rss/abc/?type=555 [R=301,L]
How can I use htaccess to redirect everything to /path/index.php
Absolutely everything including 404's, and non existing paths.
RewriteEngine On
RewriteRule ^(.*)$ /path/index.php [NC,R,L]
I have used the following to rewrite urls on my website
RewriteRule writers/(.*)/ writer-pages.php?page_name=$1
RewriteRule writers/(.*) writer-pages.php?page_name=$1
which works fine, but I have old pages that have an extension /writers/name-here.php and the rewrite above removes the .php how can I redirect the old .php to the the urls without the extension.
Another problem is I don't want redirect all .php pages
Any idea how I can do this. Any help would be much appreciated
RewriteRule writers/(.*).php writers/$1/
you can test your rewrite rules at rewrite-rule-tester
Your 2 rules can be combined into one.
You need an additional rule.
Here is the code:
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /+writer-pages\.php\?page_name=([^\s&]+) [NC]
RewriteRule ^ writers/%1? [R=302,L]
# your original rule
RewriteRule writers/([^/]*)/?$ writer-pages.php?page_name=$1 [L,QSA]
I have read about htaccess redirect and rewrite on stackoverflow and on other sites and learned how to redirect simple pages and directories, but there are about 30 links remaining that I haven't been able to redirect. The reason appears to be because they contain "?" in the link's URL. I've tried the solutions posted but I haven't been able to make enough sense of them to succeed.
These work:
Redirect /Corpfleet.php htp://www.marketyourcar.cm/wraps.php
Redirect /drivers.php htp://www.marketyourcar.cm/drivers.php
Redirect /galleries.php htp://www.marketyourcar.cm/galleries.php
These do NOT work:
Redirect /ad.php?View=FAQ htp://www.marketyourcar.cm/advertiser-faqs.php
Redirect /ad.php?View=gallery htp://www.marketyourcar.cm/galleries.php
Redirect /ad.php?View=Materials htp://www.marketyourcar.cm/products-services.php
Yes, I know that the URL above is htp and .cm - I had to break it in order to make this post with my low reputation level.
If anyone can help with this I'd appreciate it.
Thanks
If you want to redirect from like:
site.com/index.php?blabla=1&id=32
to
site.com/contact.html
then use:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} blabla=1&id=32
RewriteRule ^(.*)$ http://www.site.com/contact.html? [R=301,L]
</IfModule>
Redirect can't handle that. RewriteRule can. This should work.
RewriteEngine on
RewriteRule ^/ad\.php\?View\=FAQ$ http://www.marketyourcar.cm/advertiser-faqs.php [R=301,L]
RewriteRule ^/ad\.php\?View\=gallery$ http://www.marketyourcar.cm/galleries.php [R=301,L]
RewriteRule ^/ad\.php\?View\=Materials$ http://www.marketyourcar.cm/products-services.php [R=301,L]
Or try this:
RewriteEngine on
RewriteRule ^/ad.php?View=FAQ$ http://www.marketyourcar.cm/advertiser-faqs.php [R=301,L]
RewriteRule ^/ad.php?View=gallery$ http://www.marketyourcar.cm/galleries.php [R=301,L]
RewriteRule ^/ad.php?View=Materials$ http://www.marketyourcar.cm/products-services.php [R=301,L]
This might work:
Example:
RewriteEngine On
RewriteRule ^/ad.php?View=FAQ$ http://www.marketyourcar.cm/advertiser-faqs.php? [R=301,L]
Add a trailing ? to the substitution URL to remove the incoming query.
I'm trying to do a permanent redirect with .htaccess, but it isn't working and I have no idea why.
RedirectPermanent / http://www.flunchinvite.fr
I'm trying to do a redirection from : http://www.flunchinvite.com to: http://www.flunchinvite.fr.
Do you have any ideas?
Thanks
edit
I've just did a test to do a redirect to google, and it doesn't work either, whereas when I try to do a redirect with the same code on http://flunchinvite.fr it works. Do you know where that can come from ?
Try something similar to
//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^flunchinvite.com[nc]
RewriteRule ^(.*)$ http://www.flunchinvite.cfr/$1 [r=301,nc]
Use Rewrite if it is an option:
http://www.gnc-web-creations.com/301-redirect.htm
Another method we can use is via mod_rewrite. This requires that the
mod_rewrite module is active on your webserver. It usually is and is
done by the system administrators when they installed the webserver.
mod_rewrite is a very powerful URL re-writing engine and we will only
by scratching a hair on its head here.
Again, in your .htaccess file
RewriteEngine ON RewriteRule ^(.*)$ http://mynewdomain.com/$1
[R=301,L]
The above example will re-map your old domain to a new one and issue a
301 status code (permanent redirect). So a request for
http://olddomain.com/foobar.html will go to
http://mynewdomain.com/foobar.html
If you simply want to redirect all requests regardless of the page
requested to the new domain you could use:
RewriteRule /.* http://mynewdomain.com/ [R=301,L]
In this case no matter what file or directory is requested they will
all go to
http://mynewdomain.com/ i.e., http://myolddomain.com/foobar.html
will go to http://mynewdomain.com/
The [R=301,L] means redirect the client and send a 301 status code
(R=301) and make this the last rule (L).
At the end I did a php redirection, I don't know why it's not ok on the htaccess. I'll see that another time. I'm going to bed
Take a look at lines 5 and 6:
AddDefaultCharset UTF-8
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /demo2
RewriteCond %{HTTP_HOST} ^mathpdq\.com
RewriteRule ^(.*)$ http://www.mathpdq.com/demo2/$1 [R=permanent,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I could not get 301 redirects to work so I went with this. basically if the user goes in with mathpdq.com/demo2 it forces a redirect to www.mathpdq.com/demo2.
The stuff below line 6 is just the normal mapping into the php functions.
http://pastie.org/5364605