Robert E. McIntosh
Robert E. McIntosh

Reputation: 6125

htaccess URL Rewrite trying to simplify current one

So I have an htaccess file already that works fine, but I want to change it from having a bunch of parameters to only one.

so my current htaccess file looks like this:

Options +FollowSymLinks

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !/(_modules|css|files|fonts|ico|img|js)/
RewriteRule ^([^/]*|)/?([^/]*|)/?([^/]*|)/?([^/]*|)/?([^/]*|)/?([^/]*|)/?([^/]*|)/?([^/]*|) index.php?p1=$1&p2=$2&p3=$3&p4=$4&p5=$5&p6=$6&p7=$7&p8=$8 [L,QSA]

so I modified it to look like this: Options +FollowSymLinks

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !/(_modules|css|files|fonts|ico|img|js)/
RewriteRule ^([^/]*|)/? index.php?p1=$1 [L,QSA]

but all of the sudden none of my css, or external files work anymore.

Does anyone have any suggestions how how to get a htaccess url to work so that it can change a url from

http://www.example.com/template/index.php?controller=blog/i-am-a-title

to

http://www.example.com/template/blog/i-am-a-title

and still have it so css/style.css works

Upvotes: 1

Views: 87

Answers (2)

anubhava
anubhava

Reputation: 784918

Can you try this rule:

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/(index\.php|(_modules|css|files|fonts|ico|img|js)/)
RewriteRule ^([^/]+)/?$ /index.php?p1=$1 [L,QSA]

Also use absolute path in your css, js, images files rather than a relative one. Which means you have to make sure path of these files start either with http:// or a slash /.

Upvotes: 3

Jon Lin
Jon Lin

Reputation: 143856

Try adding this to your page's header:

<base href="/template/">

If your styles are all relative links, then when the URL changes to /template/blog/i-am-a-title, the relative URL base changes to /template/blog/ and your relative links will all break.

Upvotes: 1

Related Questions