[英]htaccess rewrite rule with single parameter
當用戶輸入URL像
http://example.com/app/abcd123/
我想顯示他的頁面
http://example.com/app/index.php?param=abcd123
如果沒有更改瀏覽器的URL。
我把.htaccess文件的應用程序文件夾中的代碼
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/index.php [NC]
RewriteCond %{QUERY_STRING} ^param=(.*)
RewriteRule (.*) http://example.com/app/%1? [R=301,L]
您可以在/app/.htaccess
使用此代碼:
RewriteEngine on
RewriteBase /app/
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /index\.php\?param=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L,NE]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?)/?$ index.php?param=$1 [L,QSA]
試試這個.htaccess
代碼。 它應該可以幫助你。
確保重寫基礎應該是您當前目錄的根目錄。
RewriteBase /app/
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ index.php?param=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ index.php [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ index.php [QSA,NC,L]
在這種情況下,如果用戶輸入像http://example.com/app/qwerty
呼叫將像http://example.com/app/index.php?params=qwerty
這應該有效,我測試過。 如果您遇到任何麻煩,請告訴我。
RewriteEngine On
RewriteBase /app
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php?param=$1 [L]
在那里檢查: http : //htaccess.mwl.be/或其他在線 htaccess 測試服務
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.