Welcome to WebmasterWorld Guest from 23.22.240.119

Forum Moderators: Ocean10000 & incrediBILL & phranque

mod rewrite: problem with 2. parameter

     
1:57 pm on Dec 10, 2017 (gmt 0)

New User

joined:Dec 10, 2017
posts:1
votes: 0


hello, I have a problem with my htaccess for mod_rewrite, here is my htaccess :

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/^\.]+)$ /index.php?id=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/([^/]+)$ /$1?action=$2 [QSA,L]


I can visit /42 without problems, but if I visit /42/views the assets are not loaded and there is no css, but why ? what have I to change ? The 2. parameter is just optional, you should be able to visit the site with one or 2 parameters. thanks for help! :D
8:33 pm on Dec 10, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:14383
votes: 567


It's hard to give a comprehensive answer without knowing what physical files actually exist on the site. Page files, that is, not “assets”. It sounds as if not everything involves /index.php alone.

^([^/^\.]+)$
Is this meant to be
^([^/.]+)$
? You don't have literal ^ characters in your URLs do you? I'm assuming this is for any request in the form
/filename
no extension, no directories.

The second rule seems awkward. Does it mean something like
/filename/blahblah
rewritten to
/filename?action=blahblah
? If so, what the heck is /filename/ (the $1 element)? Can it contain literal . periods and/or additional directory slashes? Seems like you would be going around in circles, since you're rewriting to something that is, itself, not a physical file.

the assets are not loaded and there is no css
99 times out of 100, this happens because a page contains relative links that are no longer correct after rewriting. The 100th time it is because requests for assets are themselves getting rewritten.

Suggestion: before the current rules, have something that says
RewriteRule \.(css|jpg|png|js)$ - [L]
giving any extensions that you actually use for supporting files. This will prevent later rewrites firing by accident--and it will save your server from having to do those labor-intensive -f and -d lookups.

I don't know how much of your RewriteRules you left out for posting, but also make sure there's a preceding rule for
RewriteRule ^index\.php - [L]
12:36 am on Dec 11, 2017 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11144
votes: 116


welcome to WebmasterWorld [webmasterworld.com], Waden!
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members