簡體   English   中英

.htaccess-用斜杠“ /”替換連字符(破折號)“-”

[英].htaccess - Replace hyphen (dash) '-' with a foward slash '/'

我對.htaccess有問題

這時候我有這樣的事情:

http://example.com/page-example?getVariable=1234

但我想要類似的東西:

http://example.com/page/example/1234

我試圖用.htacces代替斜杠

Options +FollowSymlinks -MultiViews
RewriteRule ^([^/]+)-([^/]+).php/?$ /$1/$2 [R,L]

我有這樣的東西

 http://example.com/page/example?getVariable=1234

但是服務器找不到路徑,我認為這是因為它承認“頁面”是文件夾。

我該怎么做,但服務器在根文件夾中搜索文件“ page-example.php”,而不在“ / page /”中搜索“ example.php”?

PS:我已經在使用下面的代碼來刪除.php擴展名和'www'。 從URL。

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

在已有規則之前,請嘗試添加:

RewriteCond %{THE_REQUEST} \ /+page-([^/]+)(?:\.php|)\?getVariable=([^&\ ]+)
RewriteRule ^ /page/%1/%2? [L,R]

RewriteRule ^page/([^/]+)/([^/]+)$ /page-$1.php?getVariable=$2 [L,QSA]

這樣整個事情看起來像:

RewriteEngine on

RewriteCond %{THE_REQUEST} \ /+page-([^/]+)(?:\.php|)\?getVariable=([^&\ ]+)
RewriteRule ^ /page/%1/%2? [L,R]

RewriteRule ^page/([^/]+)/([^/]+)$ /page-$1.php?getVariable=$2 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

暫無
暫無

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

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