Problem when htaccess rule is apllied

The head section in one of my webpages has links to various JS files/plugins:

   <script src="js/jquery-1.11.1.min.js" ></script>
    <script src="js/jquery.validate.js" ></script>
    <script src="js/jquery-ui 1.11.2.js"></script>
    <script src="js/jquery.bootpag.min.js" ></script>
    <script src="js/footer.js" ></script>
    <script src="js/html-inspector.js" ></script>

All the above in the following page:http://localhost/Appointments/Frontend/blog_show.php
In my htaccess file I have this rule:

RewriteRule ^blog_show/(.*)$ blog_show.php/?t=$1 [NC,L]

So I rewriting takes place when the user types this in the web address bar:

http://localhost/Appointments/Frontend/blog_show/2016-07-28/

blog_show.php is called again but with a query string and here the problem appears.
The js files/plugins do not load correctly…the console emit this error:
https://onedrive.live.com/redir?resid=BE27434B2AAC8130!456&authkey=!ABzaukrkGCA9W80&v=3&ithint=photo%2cPNG

I do not have the slightest idea why this happens…

my htaccess has these directives inside of it.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} \.(css|js)$
RewriteRule ^blog_show/(.*)$ blog_show.php/?t=$1 [NC,L]

the rewriting condition is for excluding css/js files from rewriting and it works.
The problem is the RewriteRule…it seems that is not happening at all…I have a 404 message from the server.

For example clicking this link:/blog_show/2016-07-25/an–offer, I get
the requested URL was not found on the server…no rewriting takes place.

dt,

First post:

  1. The directory blog_show should be different than the file blog_show.php. Which is it you’re linking to? OR are you using the horrid Options MultiViews (you must be to have blog_show.php in the path to {DirectoryIndex} with a query string). Argh!

  2. Where is your .htaccess located, Frontend?

  3. “t=2016-07-28/”? Again, why the trailing /?

  4. That looks like something from M$. While M$ tries to copy Apache’s mod_rewrite, they serve it in too many flavors to make any sense of what they’re doing at all.

Second post:

  1. Your RewriteCond specifies the requirement to HAVE either .css or .js as the file extension. It simply cannot exclude those file types without the ! (negative/not) modifier before the backslash.

  2. Same comments as above about MultiViews and trailing slashes.

[rant #1][indent]The use of “lazy regex,” specifically the :fire: EVERYTHING :fire: atom, (.*), and its close relatives, is the NUMBER ONE coding error of newbies BECAUSE it is “greedy.” Unless you provide an “exit” from your redirection, you will ALWAYS end up in a loop![/indent][/rant #1]

I should also create a rant for using the No Case flag on case SENSITIVE variables, i.e., RewriteRule which can only try to match the case SENSITIVE {REQUEST_URI}.

Yes, you used both because some tutorials showed them without explaining the adverse affects they have. My advise is to learn what code does before using it.

You might benefit from reading the mod_rewrite tutorial (http://dk.co.nz/seo) as it contains explanations and sample code. It’s helped may members and should help you, too.

Regards,

DK

I managed to solve my problem by using absolute URLs for the JS/CSS scripts.

P.S I have answered some of your questions…look closely at the quote box.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.