Kenton de Jong
Kenton de Jong

Reputation: 995

htaccess To Work For Slash and No Slash

I have a website, say: example.com and on it they have blogs, so it would be something like, example.com/?page=blog&slug=this-is-a-blog

I'm using htaccess to change it from that, to example.com/blog/this-is-a-blog, but it doesn't seem to be working. It DOES however work if I go: example.com/blog/this-is-a-blog/ (note the trailing slash).

I would like it to work both ways, if possible. My htaccess code, and I honestly have no idea what I'm doing so this may be totally wrong, looks like the following:

Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/$ /?slug=$1&blog=$2 [L]

I tried:

RewriteRule ^([^/]*)/([^/]*)/$ /?slug=$1&blog=$2 [L]
RewriteRule ^([^/]*)/([^/]*)$ /?slug=$1&blog=$2 [L]

but that just got all the links (css, js, imgages, etc.) broken on my page.

Thank you!

Upvotes: 0

Views: 52

Answers (2)

Felipe Alameda A
Felipe Alameda A

Reputation: 11809

Have to exclude existing files and directories, like this:

Options +FollowSymLinks -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/? /?slug=$1&blog=$2 [L]

Upvotes: 1

undone
undone

Reputation: 7888

try this one:

RewriteRule ^([^/]*)/([^/]*)/?$ /?slug=$1&blog=$2 [L]

Upvotes: 0

Related Questions