Removing trailing slash for sub directory url inde

2020-04-20 22:10发布

问题:

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]