I want to do this
website.com/blog/index.php -> website.com/blog
website.com/admin/archief_login.php -> website.com/admin
this works with my code.
but I want to add this:
website.com/aa -> website.com/web/index.php?init=aa
for some reason the blog gets this redirect: website.com/blog/?init=blog
what is the best way to set these different rewrites?
RewriteEngine on Options All -Indexes
RewriteCond %{HTTP_HOST}
^websit.com$ [OR] RewriteCond
%{HTTP_HOST} ^www.website.com$
RewriteRule ^admin$
"http\:\/\/www.website.com\/admin/archief_login.php"
[R=301,L]
RewriteRule ^blog$
"http\:\/\/www.website.com\/blog/index.php"
[R=301,L]
DirectoryIndex client_login.php
RewriteRule
^screen-([a-zA-Z0-9_-]+).html$
index_client.php?screen=$1
RewriteRule
^invoice([a-zA-Z0-9_-]+).html$
make_invoice.php?id=$1
RewriteRule
^pack-([a-zA-Z0-9_-]+).html$
index_client.php?screen=pack_code&wwwcode=$1
You need to put the more "general" rules lower in the file so they don't match almost all of your URLs
RewriteRule ^(\w)$ /web/index.php?init=$1 [L, NC]
RewriteRule ^blog$ /blog/index.php [R=301,L]
The above will do
website.com/aa => website.com/web/index.php?init=aa
website.com/blog => website.com/web/index.php?init=blog
If you reverse the two rules you will get
website.com/aa => website.com/web/index.php?init=aa
website.com/blog => website.com/blog/index.php
Related
Here is what I want to do:
travel.xx.com => xx.com/travel
travel.xx.com/fun => xx.com/fun
travel.xx.com/page.htm => xx.com/page.htm
health.xx.com => xx.com/health
health.xx.com/food => xx.com/food
health.xx.com/page2.htm => xx.com/page2.htm
Here is my htaccess rules:
RULE SET NUM 1:
//to convert subdomain.xx.com to xx.com/subdomain and subdomain.xx.com/WHATEVER to xx.com/subdomain/WHATEVER
RewriteCond %{HTTP_HOST} ^health.xx.com$ [NC]
RewriteRule ^(.*)$ http://xx.com/health/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^travel.xx.com$ [NC]
RewriteRule ^(.*)$ http://xx.com/travel/$1 [R=301,L]
RULE SET NUM 2:
to convert xx.com/subdomain/WHATEVER to xx.com/WHATEVER
RewriteRule ^(travel|health)(\/)([a-zA-Z0-9\&^\-\_\!\:\,\.\']+)?$ $3 [R=301,L]
Rule set number one and number two work fine separately. When I put them together, rule number 2 stops working and redirects to the root.
Can anyone tell me what I am missing here or give me a solution for this?
Thanks,
Instead of 3 rules shown you just need these 2 rules doing same thing:
RewriteCond %{HTTP_HOST} ^(health|travel)\.(xx\.com)$ [NC]
RewriteRule ^/?$ http://%2/%1/ [R=302,L,NE]
RewriteCond %{HTTP_HOST} ^(health|travel)\.(xx\.com)$ [NC]
RewriteRule ^(.+)$ http://%2/$1 [R=302,L,NE]
Make sure to keep this code before other rules.
i tried and tried with examples posted here, but i didn't manage to make my htaccess run properly.
Here's the situation:
i have links looking like this
domain.com/sport/football/index.php?lang_id=1&page_id=500 (home page)
domain.com/sport/football/index.php?lang_id=1&page_id=505 (players)
domain.com/sport/football/index.php?lang_id=1&page_id=510 (coaches) ...
i would like to rename them to
domain.com/sport/football/
domain.com/sport/football/players/
domain.com/sport/football/coaches/
etc...
and for all non-designated page_id's to redirect to home page.
All help is very much appreciated.
In the htaccess file in your document root, add:
RewriteEngine On
RewriteRule ^sport/football/$ /sport/football/index.php?lang_id=1&page_id=500 [L,QSA]
RewriteRule ^sport/football/players/?$ /sport/football/index.php?lang_id=1&page_id=505 [L,QSA]
RewriteRule ^sport/football/coaches/?$ /sport/football/index.php?lang_id=1&page_id=510 [L,QSA]
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /sport/football/index\.php
RewriteCond %{QUERY_STRING} ^(.*)page_id=500($|&)
RewriteRule ^ /sport/football/? [L,R=301]
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /sport/football/index\.php
RewriteCond %{QUERY_STRING} ^(.*)page_id=505($|&)
RewriteRule ^ /sport/football/players/? [L,R=301]
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /sport/football/index\.php
RewriteCond %{QUERY_STRING} ^(.*)page_id=510($|&)
RewriteRule ^ /sport/football/coaches/? [L,R=301]
You can use RewriteMap Directive for that. You must define the mapping from names to ids
players 505
coaches 510
and tell Apache about the map
RewriteMap football txt:/path/to/footballmap.txt
The RewriteMap must be in either the main configuration file or inside a VirtualHost directive.
Now you can use this map
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^sport/football/(.*)/?$ /sport/football/index.php?lang_id=1&page_id=${footballmap:$1|500} [L]
If there's no key found, the default 500 (homepage) will be used. If you have lots of mappings, you can also use a hashfile instead.
Update:
When you don't have access to the server or virtual host configuration file, you can only have a fixed RewriteRule "map"
RewriteRule ^sport/football/players/?$ /sport/football/index.php?lang_id=1&page_id=505 [L]
RewriteRule ^sport/football/coaches/?$ /sport/football/index.php?lang_id=1&page_id=510 [L]
# maybe other similar rules ...
# this is a catch everything else and must come last
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^sport/football/ /sport/football/index.php?lang_id=1&page_id=500 [L]
I want to redirect feedback.domain.de to www.domain.de/de/abc/cde.html via htaccess.
My current htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.de$
RewriteRule ^(.*)$ http://www.domain.de/$1 [L,R=301]
SO, I thought just to add:
redirect 301 feedback.domain.de www.domain.de/de/abc/cde.html
but it doesn't work. If i try to open feedback.domain.de it redirects to www.domain.de
I know this is a very easy question but I don't how solve it in htaccess :-(
The result I want is:
domain.de -> www.domain.de/de/index.html
www.domain.de -> www.domain.de/de/index.html
domain.de/de/example.html -> www.domain.de/de/example.html
etc...
feedback.domain.de -> www.domain.de/de/feed.html
Best regards
The Redirect directive only accept a path relative to the root path (for example /my-path) and won't match on the host part of the URL.
Try this (note that here I assume you want to redirect domain.de to www.domain.de and not all subdomains):
RewriteEngine On
# Redirect feedback.domain.de to http://www.domain.de/de/abc/cde.html
RewriteCond %{HTTP_HOST} ^feedback\.domain\.de$
RewriteRule . http://www.domain.de/de/abc/cde.html [L,R=301]
# Redirect domain.de to www.domain.de
RewriteCond %{HTTP_HOST} ^domain\.de$
RewriteRule . http://www.domain.de/$0 [L,R=301]
Updated answer (2013-03-18):
# Redirect feedback.domain.de to http://www.domain.de/de/abc/cde.html
RewriteCond %{HTTP_HOST} ^feedback\.(domain\.(de))$
RewriteRule .+ http://www.%1/%2/feed.html [L,R=301]
# domain.de -> www.domain.de/de
RewriteCond %{HTTP_HOST} ^(domain\.(de))$
RewriteRule .+ http://www.%1/%2/$0 [L,R=301]
# www.domain.de/de -> www.domain.de/de/index.html
RewriteCond %{HTTP_HOST} ^www\.domain\.(de)$
RewriteRule ^%1/?$ index.html [L,R=301]
My current .htaccess file looks like this:
RewriteEngine on
RewriteBase /
Options +FollowSymLinks -Indexes
RewriteRule ^video/(.*)$ video.php?id=$1 [L]
RewriteRule ^video/(.*)$([a-zA-Z0-9]+) video.php?id=$1 [L]
RewriteRule ^tag/(.*)/page-(.*)/$ tag.php?tag=$1&page=$2 [L]
RewriteRule ^tag/(.*)/page-(.*)$ tag.php?tag=$1&page=$2 [L]
RewriteRule ^tag/(.*)?$ tag.php?tag=$1
RewriteRule ^page/(.*)$ page.php?id=$1 [L]
RewriteRule ^feed feed.php [L]
i want to add a slash to all my url's
like this:
> example.com/video/video_id/
>
> example.com/tag/keyword/
>
> example.com/tag/keyword/page-2/ (3... and so on...)
>
> example.com/page/name/
>
> example.com/feed/
And i want to redirect my current links to the new slash url's
Can somebody help me, please?
Your current htaccess file supports a trailing / although you probably would prefer
RewriteRule ^video/(.*)/$ video.php?id=$1 [L]
So that you don't have to handle the / in video.php
Just update all of your URLs to be example.com/video/video_id/ instead of example.com/video/video_id in whatever you are using (your framework/flat HTML files).
Your old URLs will still work. If you really want to redirect them, you can:
RewriteCond %{REQUEST_URI} ^video/ [NC]
RewriteRule ^video/(.*)$ video.php?id=$1 [L,R=301]
The [NC] means No-case checking (so /VIDEO) would work. The [R=301] means permanent redirect (useful for SEO).
Go through and expand for your other rules.
Edit:
Sorry, I don't think it was quite right before. Try the following:
RewriteEngine on
RewriteBase /
Options +FollowSymLinks -Indexes
RewriteCond %{REQUEST_URI} ^video/ [NC]
RewriteRule ^video/(.*)$ video/$1/ [L,R=301]
RewriteRule ^video/(.*)/$ video.php?id=$1 [L]
RewriteCond %{REQUEST_URI} ^tag/ [NC]
RewriteRule ^tag/(.*)/page-(.*)$ tag/$1/page-$2/ [L,R=301]
RewriteRule ^tag/(.*)/page-(.*)/$ tag.php?tag=$1&page=$2 [L]
...
I am trying to perform the following rule in htaccess:
www.domain.com/folder/?id=14077&c=en-gb -> www.domain.com/folder/?id=14077
www.domain.com/folder/?c=en-gb&ID=14077 -> www.domain.com/folder/?id=14077
www.domain.com/folder/?id=14077&c=fr-fr -> www.domain.fr/folder/?id=14077
www.domain.com/folder2/?c=fr-fr&ID=14077 -> www.domain.fr/folder2/?id=14077
www.domain.com/folder2/?c=en-us&ID=14077 -> www.domain.us/folder2/?id=14077
Basically take out the "c" part of the querystring and redirect it to a new domain, based on the following rules:
c=en-gb -> www.domain.com
c=fr-fr -> www.domain.fr
c=en-us -> www.domain.us
Any help welcome!
Admittedly, I'm not sure if this is a task best solved by mod_rewrite...but what the hell, why not:
(Not fully tested, but it seems to work well)
RewriteEngine On
RewriteCond %{QUERY_STRING} (.*)(\A|&)c=([A-Za-z\-]+)&?(&.*)?$
RewriteRule .* - [E=SWITCHLANG:%3,E=QSONE:%1,E=QSTWO:%4]
RewriteCond %{ENV:SWITCHLANG} =en-gb [NC]
RewriteCond %{HTTP_HOST} !(.*)\.com$
RewriteRule (.*) http://www.domain.com/$1?%{ENV:QSONE}&%{ENV:QSTWO}
RewriteCond %{ENV:SWITCHLANG} =fr-fr [NC]
RewriteCond %{HTTP_HOST} !(.*)\.fr$
RewriteRule (.*) http://www.domain.fr/$1?%{ENV:QSONE}&%{ENV:QSTWO}
RewriteCond %{ENV:SWITCHLANG} =en-us [NC]
RewriteCond %{HTTP_HOST} !(.*)\.us$
RewriteRule (.*) http://www.domain.us/$1?%{ENV:QSONE}&%{ENV:QSTWO}