mod_rewrite: add trailing slash?

前端 未结 4 981
心在旅途
心在旅途 2020-12-31 11:41

I am using a .htaccess file to direct requests for a directory to a custom php file that provides info about that directory (and i want the url displayed by the browser to n

4条回答
  •  北海茫月
    2020-12-31 12:27

    Did you mean

    RewriteRule ^(.*)$ $1/ [L]
    

    instead?

    I don't know about your approach. I would try something like

    RewriteRule ^/(\S+)/?$ /myphp.php?url=$1
    

    I've used this for rewriting before and it works:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^domain\.com
    RewriteRule ^(.*)$ http://www.domain.com$1
    RewriteRule ^/(\S+)/?$ /myphp.php?url=$1
    

    Note that I didn't include the trailing slash in the first rule.

    Also, I would advice you not to rely on .htaccess unless absolutely necessary. This is because the server will check for .htaccess files constantly. Using the httpd.conf file instead means apache will only load conditions and rules once. At least I was adviced to do so because of this.

提交回复
热议问题