Home > database >  RewriteRule - css is missing if I add last slash inside url
RewriteRule - css is missing if I add last slash inside url

Time:07-28

I want example.com/video/ - with or without last slash - to be interpreted as example.com/video.php - and this works

example.com/video/5/lorem-ipsum/ - with or without last slash - should be interpreted as example.com/video.php?id=5&s=lorem-ipsum

it works only without last /
with that slash - the content is there but css is missing

please help

<base href='../../'>

RewriteRule ^video/?$ video.php [L]
RewriteRule ^video/([^/]*)/(.*)/?$ video.php?id=$1&s=$2 [QSA,NC,L]

CodePudding user response:

With your shown samples please try following htaccess rules file. Please make sure that your .htaccess file is residing along with your video.php file. Also make sure to clear your browser cache before testing your URLs.

RewriteEngine ON

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(video)/(\d )/([^/]*)/?$ $1.php?id=$2&s=$3 [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(video)/?$ $1.php [QSA,NC,L]

JS/CS rewrite/redirect: You may need to use base tag to fix your js and other relative resources. If you are linking js files using a relative path then the file will obviously get a 404 because its looking for URL path. for example if the URL path is /file/ instead of file.html then your relative resources are loading from /file/ which is not a directory but rewritten html file. To fix this make your links absolute or use base tag. In the header of your webpage add this <base href="/"> so that your relative links can load from the correct location.

  • Related