I am trying to create redirections from the old urls to the new ones and I have a problem how to write appropriate htaccess rules.
old urls
domain.com/cat1/cat2/cat3/city,name
domain.com/cat1/cat2/city,name
domain.com/cat1/city,name
new urls
domain.com/cat1/cat2/cat3?city=name
domain.com/cat1/cat2?city=name
domain.com/cat1?city=name
I tried something like this but it doesn't work.
RewriteRule ^/city,(.*)$ /city=?$1 [L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^,]*),(.*)/?$ $1/$2/$3?$4=$5 [L]
RewriteRule ^([^/]*)/([^/]*)/([^,]*),(.*)/?$ $1/$2?$3=$4 [L]
RewriteRule ^([^/]*)/([^,]*),(.*)/?$ $1?$2=$3 [L]
RewriteCond %{HTTP_HOST} ^www\.domain\.pl [NC]
RewriteRule ^(.*)$ http://domain.pl/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{HTTP_HOST} !^www\.domain.pl
RewriteCond %{HTTP_HOST} ^(.+).domain.pl
RewriteRule ^([^/]*)$ http://domain.pl/account/firma/%1 [P,L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
EDIT: As per OP's edit adding following now.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.pl [NC]
RewriteRule ^(.*)$ http://domain.pl/$1 [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.domain.pl
RewriteCond %{HTTP_HOST} ^(.+).domain.pl
RewriteRule ^([^/]*)$ http://domain.pl/account/firma/%1 [P,L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^,]*),(.*)/?$ $1/$2/$3?$4=$5 [L]
RewriteRule ^([^/]*)/([^/]*)/([^,]*),(.*)/?$ $1/$2?$3=$4 [L]
RewriteRule ^([^/]*)/([^,]*),(.*)/?$ $1?$2=$3 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
With your shown samples, could you please try following. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
##To deal with domain.com/cat1/cat2/cat3/city,name URLs
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^,]*),(.*)/?$ $1/$2/$3?$4=$5 [L]
##To deal with domain.com/cat1/cat2/city,name URLs
RewriteRule ^([^/]*)/([^/]*)/([^,]*),(.*)/?$ $1/$2?$3=$4 [L]
##To deal with domain.com/cat1/city,name URLs
RewriteRule ^([^/]*)/([^,]*),(.*)/?$ $1?$2=$3 [L]
You can try this full .htaccess code. Make sure you don't have anything extra apart from this code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?!www\.)(.+)\.(domain\.pl)$ [NC]
RewriteRule ^ http://%1/account/firma%{REQUEST_URI} [P,L]
RewriteCond %{HTTP_HOST} ^www\.(domain\.pl)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/([^,]+),([^/]+)/?$ $1?$2=$3 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Also make sure to clear your browser cache completely before testing this change.
Related
Stay On multi Url htaccess https://example.com/**toko**/login and on click stay https://example.com/**toko**/home....
please help me, because I don't really understand and explore htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /modchan
#RewriteRule ^([0-9]+)$ ?x=$1
RewriteCond %{REQUEST_URI} !^/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.tld$ [NC]
RewriteRule ^(.*)$ /public/$1 [L]
#RewriteRule ^ index.php [L]
#RewriteRule ^(/)?$ public/index.php [L]
</IfModule>
I have Codeigniter 3 project in root directory. I need to use it with kohana other project which is in subfolder (admin).
I need to make redirect, when I will type mysite.xyz/admin that will redirect me to subfolder admin, where are kohana files: index.php etc.
Now CodeIgniter think that admin is a controller.
My .htacces file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /projekty/folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteRule admin/^(.*)$ /admin/ [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Have any ideas, how to solve that? I was trying to find some solutions, but no success.
Here is Kohana .htaccess:
RewriteEngine On
RewriteBase /projekty/folder/admin/
###### Add trailing slash (optional) ######
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [L,R=301,NE]
RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^(.*)home/u343855449/public_html/projekty/folder/admin/index.php/(.*)$ /$1$2 [R=301,L,NE]
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|media)
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?kohana_uri=$1 [L,QSA]
your admin rule is in the wrong place. It needs to come before the CI rules. Put it below the rewritebase. Try these rules.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /projekty/folder/
RewriteRule ^admin/(.*)$ /admin/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/admin [NC]
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
Actually you really don't need the admin rule. Just tell it to ignore admin in the CI rules as below.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /projekty/folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/admin [NC]
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
I'm trying to exclude few URI from htaccess based redirection
My htaccess directives are bellow
<IfModule mod_rewrite.c>
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^(www\.)?domain1.com$ [NC]
RewriteRule !=/test$ http://domain2.com [L,R=301,NC]
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
What wrong in this? Any suggesion?
I have tried in a different way as well
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !=/test
RewriteRule (.*) http://domain2.com? [R=301,L]
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
While doing external redirection, exclusion of the the URI, test is not in effect. If I'm doing an internal rewrite, its working fine.
Maybe this works:
Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !/test
# Add next line
RewriteCond %{REQUEST_URI} !index\.php [NC]
RewriteRule (.*) http://domain2.com? [R=301,L]
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
I need to make this work with HTTP, HTTPS and SSL, this is my actual (working) rewrite:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
</IfModule>
But i Need to force to redirect the non "www" urls (like http://domain.com) to the same URL with the "www" AND still working the index.php?url=$1 because i need this for my "router" engine.
Thanks for the help!
This should do the work (before any other rewrite rule):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www.*$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST} !^www.*$
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [L,R=301]
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
</IfModule>
Just add the non-www to www rule at the beginning, like this:
#non-www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com/?$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
</IfModule>
I am trying to add a "/login" to wildcard subdomains.
For example:
*.example.com would be redirected to *.example.com/login
but, i want certain subdomains not to be redirected, such as...
help.example.com, m.example.com, etc.
What is the best way to do this, and would this be done in .htaccess or in httpd.conf?
Thank you for your help.
Updated below:
Here is what I currently have:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^m.example.com$
RewriteCond %{HTTP_HOST} ^(.+).example.com$ [NC]
RewriteRule ^/$ https://%1/login [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
You were almost there
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^m\.example\.com$
RewriteCond %{HTTP_HOST} !^help\.example\.com$
RewriteCond %{HTTP_HOST} ^(.+\.example\.com)$ [NC]
RewriteRule ^/?$ https://%1/login [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>