简体   繁体   中英

htaccess mod_rewrite problem with rewriting url

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/

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM