我想在URL中进行更改,例如:
localhost:8080/shop/phones/?language=ru to localhost:8080/shop/ru/phones/
我尝试了很多,但任何时候我都没有结果。
我的.htaccess:
# Turn on the rewrite engine
RewriteEngine on
ErrorDocument 404 /shop/PageNotFound.php
AddDefaultCharset windows-1251
RewriteBase /
#Default Language
####RewriteRule ^(us|de|fr|ru)/(.*)$ $2?language=$1 [L,QSA]
####RewriteRule ^(.*)$ $1?language=us [L,QSA]
# If the request doesn't end in .php (Case insensitive) continue processing
RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteCond %{REQUEST_URI} !\.css$ [NC]
RewriteCond %{REQUEST_URI} !\.png$ [NC]
RewriteCond %{REQUEST_URI} !\.jpg$ [NC]
RewriteCond %{REQUEST_URI} !\.js$ [NC]
RewriteCond %{REQUEST_URI} !\.jpeg$ [NC]
# If the request doesn't end in a slash continue processing the rules
RewriteCond %{REQUEST_URI} [^/]$
# Rewrite the request with a .php extension. L means this is the 'Last' rule
RewriteRule ^(.*)$ $1.php [L]
答案 0 :(得分:0)
这应该是你完整的htaccess:
ErrorDocument 404 /shop/PageNotFound.php
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} /shop/phones/\?language=([^\s]+) [NC]
RewriteRule ^ /shop/%1/phones? [L,R=302]
RewriteRule ^shop/([^/]+)/phones/?$ /shop/phones/?language=$1 [NC,L]
#Remove php exten
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule (.*) /$1.php [NC,L]