How is possible in .htaccess to make from subdomain
example.domain.com/gallery/index.html
into example.domain.com/gallery/
Not sure what you are trying to say with your last comment to the question. The rule I posted rewrites exactly one URL. But maybe you are looking for the opposite redirection, I just realize, so:
RewriteEngine on
RewriteRule ^/?gallery/index\.html$ /gallery/ [R=301]
RewriteRule /?gallery/?$ /gallery/index.html [END]
This redirects clients requesting /gallery/indx.html but still delivers the local file /gallery/index.html when requesting /gallery.
Related
I have a file at example.com/DesktopModules/SubscriptionSignup/Tools/IPNHandler.aspx that needs to be rewritten so that it actually runs example.com/paypal-ipn-handler.php.
All other traffic, though, should be redirected to another-example.com.
I'm using this in my .htaccess file:
# Rewrite IPNHandler.aspx to paypal-ipn-handler.php
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} ^/Tools/IPNHandler.aspx [NC]
RewriteRule ^.*$ https://www.example.com/paypal-ipn-handler.php [P]
</IfModule>
#Redirect all other traffic to new domain.
RewriteRule ^ https://www.another-example.com%{REQUEST_URI} [L,R=301]
However, that's redirected everything including the URL that should stay at this domain, but get re-written to the PHP file.
For example, with the above in place, I would expect that traffic to example.com/DesktopModules/SubscriptionSignup/Tools/IPNHandler.aspx would remain at example.com, but run the PHP script instead. This is not happening, though. It's getting redirected to another-example.com/..../IPNHandler.aspx and gives me a 404, of course.
Any information about how I can adjust this so that my rewrite works and stays on the original domain, but all other traffic gets redirected would be greatly appreciated. Thanks!
EDIT
Actually, I commented out the redirect to see if my rewrite was working, and it's actually giving me a 404, but when I hit the paypal-ipn-handler.php directly I get the output I expect.
So it seems I need more help than I thought, please, and thanks!
You may use these rules in your site soot .htaccess:
RewriteEngine On
RewriteRule Tools/IPNHandler\.aspx$ /paypal-ipn-handler.php [L,NC]
#Redirect all other traffic to new domain.
RewriteRule !^paypal-ipn-handler\.php$ https://www.another-example.com%{REQUEST_URI} [L,NC,NE,R=301]
There is no need to use P flag here as you just want an internal rewrite.
Condition !^paypal-ipn-handler\.php$ will redirect everything except /paypal-ipn-handler.php.
Make sure to use a new browser to test or test after you completely clear browser cache.
I'm new at programming. We have an office project, the website's URL is www.project.com.ph (sample name), this is already a live website from the client. But the released printouts have the instructions for the users to go to www.project.com/ph which is wrong and we can't reprint the material since it already reached plenty of event places.
Now the problem is, we need to redirect to www.project.com.ph automatically if the users type in the browser's address bar www.project.com/ph. I ask if this is possible without any kind of CMS or Wordpress and how to actually do it? We bought a new domain www.project.com for this. Any kind of help is appreciated.
Try the following near the top of your .htaccess file in the root of www.project.com. This works OK (although marginally less efficient) if both domains are pointing to the same place, since it specifically checks that we are requesting the "wrong" domain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?project\.com$ [NC]
RewriteRule ^ph/?(.*) http://www.project.com.ph/$1 [NC,R=302,L]
This will redirect requests for www.project.com/ph (no slash), www.project.com/ph/ (with a trailing slash) and www.project.com/ph/<whatever> to http://www.project.com.ph/<whatever>.
This is a temporary (302) redirect. Change it to a permanent (301) only when you are sure it's working OK.
From kj.'s answer on a similar question, here
In your .htaccess for www.project.com, this should do the trick.
RewriteEngine on
RewriteRule ^(.*)$ http://www.project.com.ph/ [R=permanent,NC,L]
This will redirect any request to project.com to the domain http://www.project.com.ph/
To include the path after the /ph/` you can use this.
RewriteEngine on
# redirect including path after ph/ (e.g. project.com/ph/directory/file.php to project.com.ph/directory/file.php
RewriteRule ^ph/(.*)$ http://www.project.com.ph/$1 [R=permanent,NC,L]
# redirect any other requests to project.com.ph index
RewriteRule ^(.*)$ http://www.project.com.ph/ [R=permanent,NC,L]
You can redirect (301 redirect) the URL using RewritrRule in .htaccess file
RewriteRule "http://www.project.com/ph/(.*)" "http://www.project.com.ph/$1" [L,NC,R=301]
I'm having an issue with some htaccess rules which I thought would be simple. I have some nice SEO friendly URL rewriting in place as below
RewriteEngine On
RewriteCond %{REQUEST_URI} !^(index\.php|/images|/templates|/views|/ajax|/uploads|/robots\.txt|/sitemap\.xml|/favicon\.ico|/scripts|/cron|/combine.php|/js|/css)
RewriteRule ^(.*)$ index.php?ref=$1&%{QUERY_STRING} [L]
This all works well and I want to keep this. I also wish to rewrite some old pages which Google WMT is reporting as 404's to the new equivalent and for that I'd like to use:
Redirect 301 /about_us http://example.com/about-us
The problem I have is that the URL that the browser is directed to is:
http://example.com/about-us?ref=about_us
The about_us is the old link and about-us is the correct link. If the htaccess redirected to example.com/about-us then the other SEO friendly rewrite rule will pick it up and show the page but eh extra ?ref= parameter is confusing it. I am guessing the two rules are conflicting to a degree but is there a way to get the two rules to work together e.g. redirect without the extra ?ref= parameter? My knowledge of htaccess is basic to say the least so I am a little stuck on this one.
Thanks in advance
Redirect and RedirectMatch are part of mod_alias, while the rewrite rules are part of mod_rewrite. The problem you're running into is when you mix the two, both modules affect the same request, thus two things happen when you only want one. In this case, you need to stick with just mod_rewrite and use this instead:
RewriteEngine On
RewriteRule ^about_us /about-us [L,R=301]
RewriteCond %{REQUEST_URI} !^(index\.php|/images|/templates|/views|/ajax|/uploads|/robots\.txt|/sitemap\.xml|/favicon\.ico|/scripts|/cron|/combine.php|/js|/css)
RewriteRule ^(.*)$ index.php?ref=$1&%{QUERY_STRING} [L]
Note that the rule that redirects comes before the rule that routes to index.php.
We have an existing site, let's call it ourdomain.com. We moved content over from a site that is shutting down, let's call it legacydomain.com. We pointed the legacy domain at our server to the /public_html/ folder.
What I need is an .htaccess that will redirect legacydomain.com or legacydomain/anything-here to ourdomain.com/legacydomain/ with nothing else appended to the URL.
However, I also need a few specific URLs to redirect to certain destinations, and they don't really follow a pattern. For example:
legacydomain.com/something.html to ourdomain.com/legacydomain/something.html
legacydomain.com/another.html to ourdomain.com/legacydomain/folder/another.html
This is what I have tried:
RewriteCond %{HTTP_HOST} ^www\.legacydomain\.com$ [NC]
RewriteRule (.*) http://www.ourdomain.com/legacydomain/$1 [R=301,L]
Redirect 301 /something.html http://www.ourdomain.com/legacydomain/another.html
It mostly works, but if I visit legacydomain.com/anything-here it doesn't even attempt to rewrite, it just keeps the domain the same and gives a 404. And also I have a feeling that even if it did work, something like legacydomain.com/anything-here/more-stuff would get rewritten as ourdomain.com/legacydomain/anything-here/more-stuff which I don't want.
Only other thing in the .htaccess is rewriting non-www to www, and the standard WordPress stuff. Any guidance would be greatly appreciated. Everything above should have an http:// and www in front for the examples, but it wouldn't let me post that many "links".
For each specific rewrite you would need two lines, as follows. Depending on your existing config you may need to add a slash at the beginning of the RewriteRule in front of something.html if this doesn't work.
RewriteCond %{HTTP_HOST} legacydomain.com
RewriteRule something.html http://ourdomain.com/legacydomain/something.html [R=301,L]
Then you would use a catch-all for everything else.
RewriteCond %{HTTP_HOST} legacydomain.com
RewriteRule (.*) http://ourdomain.com/legacydomain/ [R=301,L]
Personally, I would go for the simplest solution which doesn't use mod_rewrite. First, just redirect the specific pages to wherever they need to go.
Redirect 301 /something.html http://ourdomain.com/legacydomain/something.html
Redirect 301 /another.html http://ourdomain.com/legacydomain/another.html
Then, simply redirect everything else to the base URL.
RedirectMatch 301 (.*) http://ourdomain.com/legacydomain/
These must be put in your .htaccess file before the RewriteEngine on statement.
I will soon relaunch my whole website on the same domain, and so i would like to redirect all old url's to the new homepage. I've been looking around and have found lots of ways to do that, but no one works for me. I guess i need help from someone who really understands.
The current url's are like this:
http://www.ffsolar.com/produtos/index.php?lingua=por
http://www.ffsolar.com/contacto/index.php?lingua=eng
http://www.ffsolar.com/inicio/index.php?lingua=ger
Which i want to redirect to the new
http://www.ffsolar.com
The old folders and files will no longer exist after the relaunch, so i think that the redirect 301 method won't work.
So, my question is how do i do that? Do i have to use a mod-rewrite, or a simple redirect for all the old url's?
You could use ErrorDocument 404 /
Or you create a RewriteRule for each url that no longer exists:
E.g.:
RewriteEngine on
RewriteRule ^/produtos(.*)$ / [R]
RewriteRule ^/contacto(.*)$ / [R]
RewriteRule ^/inicio(.*)$ / [R]
You could also use RewriteRule ^produtos(.*)$ http://www.ffsolar.com/ [R]
So every url with e.g. /produtos or /contacto or /inicio will be redirected to the document root of this domain.
Also http://www.ffsolar.com/produtos/index.php?lingua=por or even http://www.ffsolar.com/produtos/just/example/random.php