Friendly URLs with .htacces weird response form my web hosting… HELP

十年热恋 提交于 2020-01-24 20:56:07

问题


I just wanted that when this is inserted in the URL:

http://website.com/pelicula/0221889/
http://website.com/pelicula/0221889/posters/

It really goes to this (in background):

http://website.com/index.php?ctrl=pelicula&id=0160399
http://website.com/index.php?ctrl=pelicula&id=0160399&tab=posters

So I put this in my .htaccess file:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^/([^/]+)/([^/]+)/?([^/]*)/?$ index.php?ctrl=$1&id=$2&tab=$3 [QSA,L]
</IfModule>

But it was not working in my web host so I asked for help from their support team and this was their response:

<IfModule mod_rewrite.c>
RewriteEngine On
# If subdomain www exists, remove it first
#RewriteCond %{HTTP_HOST} ^www.([^.]+.[^.]+)$ [NC]
#RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# If requested resource does not exist as a file
RewriteCond %{REQUEST_FILENAME} !-f
# and does not end with a period followed by a filetype
RewriteCond %{REQUEST_URI} !..+$
# and does not end with a slash
RewriteCond %{REQUEST_URI} !/$
# then add a trailing slash and redirect
RewriteRule (.*) $1/ [R=301,L]
</IfModule>

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Obviously its not working as desired so I just want to know how to fix this!!! I don't know nothing about mod_rewrite and I really need this to work perfectly... I'm going mad I don't know where is the problem.. please help!


回答1:


It seems that the support guys just sent you the first URL-rewriting code they found in their knowledge base to serve as sample. And it's normal: no hosting service in the world can provide free consulting services :)

I suggest you try to keep it simple:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^/]+)/(\d+)/([^/]+)/?$ index.php?ctrl=$1&id=$2&tab=$3 [QSA,L]
    RewriteRule ^([^/]+)/(\d+)/?$         index.php?ctrl=$1&id=$2 [QSA,L]
    RewriteRule ^([^/]+)/?$               index.php?ctrl=$1 [QSA,L]
</IfModule>


来源:https://stackoverflow.com/questions/3063612/friendly-urls-with-htacces-weird-response-form-my-web-hosting-help

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