Removing trailing slash for sub directory url indexing

跟風遠走 提交于 2019-12-20 04:31:51

问题


example.com/contact.php  <- I want to like this -> example.com/contact

and this also want...

example.com/contact/ (havent real directory. want to redirect /contact)
example.com/contact.(any extension redirect to /contact)

i want to like this.. plz help me for this one

if have real directory want to go there...

Edit :

example.com/watch.php?id=1995/english-videos this link is not work.. and i want to redirect like this example.com/contact dont want slash. and i want to work this link example.com/watch.php?id=1995/english-videos

/.htaccess

RewriteEngine on

RewriteCond %{HTTP_HOST} ^col3negmovie.com$
RewriteRule ^(.*)$ "http\:\/\/www\.col3negmovie\.com\/$1" [R=301,L]


Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^col3negmovie\.com$
RewriteRule ^(.*)$ http://www.col3negmovie.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+watchnew1\.php\?id=([^\s&]+) [NC]
RewriteRule ^ watch/%1? [R=301,L]

RewriteRule ^watch/(.+?)/?$ watchnew1.php?id=$1 [L,QSA,NC]

# remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=301,L]

# remove .php extension 
RewriteCond %{THE_REQUEST} \s/+(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]

# add .php extension internally
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]

example.com/watch.php?id=1995/english-videos not work :( other link i want like this example.com/contact , example.com/about but this link want like that


回答1:


Your complete .htaccess can be like that:

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^col3negmovie\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

RewriteCond %{THE_REQUEST} \s/+watchnew1\.php\?id=([^\s&]+) [NC]
RewriteRule ^ watch/%1? [R=301,L]

# remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ $1 [R=301,L]

# remove .php extension 
RewriteCond %{THE_REQUEST} \s/+(.*?)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L,NE]

RewriteRule ^watch/(.+?)/?$ watchnew1.php?id=$1 [L,QSA,NC]

# add .php extension internally
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]


来源:https://stackoverflow.com/questions/23025518/removing-trailing-slash-for-sub-directory-url-indexing

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