URL Rewriting for sub-folder

烈酒焚心 提交于 2019-12-25 02:53:38

问题


I need a URL like this:

http://domain.com/subfolder/file.php?src=quick-brown-fox&m=1&size=320x480

.. changed to:

http://domain.com/subfolder/file/quick-brown-fox/320x480

I updated the htaccess with:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/subfolder/([^\.]+)$ $1.php [NC,L]

but I'm getting a 404. What am I doing wrong?


回答1:


You could do this in subfolder/.htaccess

Options -MultiViews
RewriteEngine On
RewriteBase /subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?(.*)$ $1.php [NC,L]

Then capture the URI in php.




回答2:


You can have this rule in /subfolder/.htaccess:

Options -MultiViews
RewriteEngine On
RewriteBase /subfolder/

RewriteRule ^(file)/([^/]+)/([^/]+)/?$ $1.php?src=$2&m=1&size=$3 [QSA,NC,L]


来源:https://stackoverflow.com/questions/29215708/url-rewriting-for-sub-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!