簡體   English   中英

Mod_rewrite的網址?

[英]Mod_rewrite for url with?

我在StackOverflow中找不到其他問題的答案。mod_rewrites生成器失敗,所以我不知道該怎么做。

我有那個網址: http : //example.com/? index&category= football

足球是由php動態生成的,因此有很多類別。 所以我想要這樣的URL: http : //example.com/football

如何使用mod_rewrite? 非常感謝!

RewriteEngine on
    RewriteRule ^/([a-zA-Z0-9]+)$ /index.php?category=$1
    #RewriteRule ^/([a-zA-Z0-9]+)/$ /index.php?category=$1

這應該使URL http://example.com/football作品仿佛http://example.com/?index&category=football使用:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^/?([^/$]*) /?index&category=$1 [L]

第2到5行(從RewriteCond %{REQUEST_FILENAME} -sRewriteRule ^.*$ - [NC,L] )是可選的:它們使任何以類別名稱(例如football )命名的現有文件直接提供(不使用/?index&category = ... )。

嘗試:

RewriteEngine On

RewriteCond %{THE_REQUEST} \ /+\?index&category=([^&\ ]+)
RewriteRule ^ /%1? [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /?index&category=$1 [L,QSA]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM