Can apache rewrite rules go in httpd.conf

走远了吗. 提交于 2019-12-21 12:14:25

问题


How do I create a simple apache rewrite rule to rewrite:

http://domain.com/vanity to http://domain.com/foo/

Also can rewrite rules go in httpd.conf or do they have to go in a .htaccess file?

Thanks in advance.


回答1:


Put this in your website's <virtualhost>.

RewriteEngine On
RewriteRule ^/vanity$ /foo/ [L]

The [L] will silently redirect, so the user will still see /vanity in the URL. You could use [R] to force a redirect.




回答2:


They go in httpd.conf. Check out the doc




回答3:


For httpd.conf, wrap 'Directory' tags around your rewrite rules. For .htaccess there's no need. It's generally considered more secure to put them in your httpd.conf however, so this is what I do.



来源:https://stackoverflow.com/questions/12941879/can-apache-rewrite-rules-go-in-httpd-conf

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