.htaccess rewrite URL for my website

♀尐吖头ヾ 提交于 2019-12-13 07:38:54

问题


maybe you can help me to rewrite my URL (i never worked with a .htacces-file).

Example: I have a URL like this: http://localhost/index.php?s=example

How i can chance this URL like this: http://localhost/example ?

Maybe you can help me.

Thank you!


回答1:


You can use the following in root/.htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php?s=$1 [NC,L]

This script will allow you to access /index.php?s=foobar using the clean url /foobar



来源:https://stackoverflow.com/questions/37785058/htaccess-rewrite-url-for-my-website

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