Reputation: 33
I'm trying to redirect the url address to a nice url. unfortunately still after a few attempts it doesn't work with this htaccess can you advise me somehow?
My htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ /$1.html
RewriteCond %{REQUEST_URI} !^subdom/
RewriteCond %{REQUEST_URI} !^/subdom/
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)\.([^\.]*)\.([^\.]*)$
RewriteCond %{DOCUMENT_ROOT}/subdom/%2 -d
RewriteRule (.*) subdom/%2/$1 [DPI]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^domains/[^/]+/(.+[^/])$ /$1/ [R]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^subdom/[^/]+/(.+[^/])$ /$1/ [R]
This dont work
RewriteCond %{QUERY_STRING} ^page=([^&]+)$
RewriteRule ^index\.php$ %1? [R=301,L,NE]
RewriteRule ^([^/]+)\.html index.php?page=$1 [L,QSA]
And this not working to
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^([^/]+)/([^/]+)/(.+)$ index.php?lang=$1&page=$2 [L,QSA]
RewriteRule ^([^/]+)/(.+)$ index.php?lang=$1 [L,QSA
I need make from this https://mypage.com/index.php?page=my-page and https://mypage.com/index.php?lang=en&page=my-page
this https://mypage.com/my-page/ and https://mypage.com/en/my-page/
Upvotes: 1
Views: 95
Reputation: 133428
With your shown sample, please try following htaccess. Added OP's already existing rules here(I removed OP's rule RewriteCond %{REQUEST_URI} !^subdom/
since REQUEST_URI variable always starts from /
so need for this rule) and appended by suggested rules in it. Please make sure you clear your browser cache before testing your URLs.
Options +FollowSymlinks
RewriteEngine ON
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ /$1.html
RewriteCond %{REQUEST_URI} !^/subdom/
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)\.([^\.]*)\.([^\.]*)$
RewriteCond %{DOCUMENT_ROOT}/subdom/%2 -d
RewriteRule (.*) subdom/%2/$1 [DPI]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^domains/[^/]+/(.+[^/])$ /$1/ [R]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^subdom/[^/]+/(.+[^/])$ /$1/ [R]
####Newly added rules here....
RewriteCond %{QUERY_STRING} ^page=(.*)/?$ [NC]
RewriteRule ^index\.php/?$ %1 [R=301,NC]
RewriteRule ^(.*)/?$ index.php?page=$1 [L]
RewriteCond %{QUERY_STRING} ^lang=([^&]*)&page=(.*)/?$ [NC]
RewriteRule ^index\.php/?$ %1/%2 [R=301,NC]
RewriteRule ^([^/]*)/(.*)/?$ index.php?lang=$1&page=$2 [L]
Upvotes: 2