[英].htaccess - Replace hyphen (dash) '-' with a foward slash '/'
I'm having a problem with .htaccess 我对.htaccess有问题
At this time I have something like this: 这时候我有这样的事情:
http://example.com/page-example?getVariable=1234
But I want something like: 但我想要类似的东西:
http://example.com/page/example/1234
I tried to use that .htacces to replace the hyphens with slashes 我试图用.htacces代替斜杠
Options +FollowSymlinks -MultiViews
RewriteRule ^([^/]+)-([^/]+).php/?$ /$1/$2 [R,L]
And I got something like this 我有这样的东西
http://example.com/page/example?getVariable=1234
But the server can't find the path, I think it's because it admits that the 'page' is a folder. 但是服务器找不到路径,我认为这是因为它承认“页面”是文件夹。
How can I do what I want to, but the server search for the file 'page-example.php' at the root folder and not for 'example.php' at '/page/' ? 我该怎么做,但服务器在根文件夹中搜索文件“ page-example.php”,而不在“ / page /”中搜索“ example.php”?
PS: I'm using already the code below to remove the .php extension and the 'www.' PS:我已经在使用下面的代码来删除.php扩展名和'www'。 from the URL.
从URL。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Before the rules that you already have, try adding: 在已有规则之前,请尝试添加:
RewriteCond %{THE_REQUEST} \ /+page-([^/]+)(?:\.php|)\?getVariable=([^&\ ]+)
RewriteRule ^ /page/%1/%2? [L,R]
RewriteRule ^page/([^/]+)/([^/]+)$ /page-$1.php?getVariable=$2 [L,QSA]
So that the whole thing looks like: 这样整个事情看起来像:
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.