Forum Moderators: phranque
Okay, my problem is the following:
http://localhost/dev/main <-- works
http://localhost/dev///////main <-- works also...
No matter how many slashes (/) I add, the url will still work.
I have tried to get rid of this and make only one slash work in my URI.
My .htaccess
-----------------------------------------------
RewriteEngine On
IndexIgnore *
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^main$ index.php?page_id=main [L]
RewriteRule ^search$ index.php?page_id=search [L]
RewriteRule ^articles/$ index.php?page_id=page_id.archive [L]
RewriteRule ^articles/(\d+)$ index.php?page_id=articles&art=$1 [L]
RewriteRule ^articles/(\d+)&pid=(\d+)$ index.php?page_id=articles&art=$1&pid=$2 [L]
------------------------------------------------------------
And so on.
I just want my pages to work http://localhost/dev/blah/bleh/bloh etc...
And when added extra slashes, they won't work.
Any idea please?
[1][[b]edited by[/b]: Saturn at 11:32 pm (utc) on Aug. 1, 2007][/1]
Be aware that RewriteConds only apply to the *single* rule that follows them. I have removed them because they don't seem necessary in these rules that affect only specific pages.
I'd suggest:
RewriteEngine on
#
# Redirect to remove multiple slashes
RewriteCond %{REQUEST_URI} ^(.*)//+(.*)$
RewriteRule / http://www.example.com%1/%2 [R=301,L]
#
# If page does not exist, rewrite request to index.php with page name in page_id query parameter
RewriteRule ^(main¦search)$ index.php?page_id=$1 [L]
#
# Rewrite /articles/ request to index.php?page_id=page_id.archive
RewriteRule ^articles/$ index.php?page_id=page_id.archive [L]
#
# Rewrite /articles/<numbers> request to index.php?page_id=articles&art=<numbers>
# and [b]retain any existing query parameters[/b] (such as pid=nnn)
RewriteRule ^articles/([0-9]+)$ index.php?page_id=articles&art=$1 [QSA,L]
# Rewrite /articles/<numbers>?pid=<number> request to index.php?page_id=articles&art=<numbers>&pid=<number>
# (Note the special construct in the RewriteCond which allows this to work even if no pid is present.)
RewriteCond &%{QUERY_STRING} ^(&pid=[0-9]+)$
RewriteRule ^articles/([0-9]+)$ index.php?page_id=articles&art=$1%1 [L]
Jim
[edited by: jdMorgan at 1:22 am (utc) on Aug. 2, 2007]
I am trying to work it out but.
RewriteCond %{REQUEST_URI} ^(.*)//+(.*)$
RewriteRule / http://localhost/dev %1/%2 [R=301,L]
( I need to use localhost as I am working locally for now.
I get this error for
http://localhost/dev/main
------------->
Server error!
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.
If you think this is a server error, please contact the webmaster.
Error 500
localhost
08/02/07 04:02:39
Apache/2.2.0 (Win32) DAV/2 mod_ssl/2.2.0 OpenSSL/0.9.8a mod_autoindex_color PHP/5.1.1
Thanks. That works in cases like
[localhost...]
Or
[localhost...]
But I am still having a small problem
If I type an extra slash (/) the URL is like this ->
http://localhost/dev//dev/dev/dev/dev/dev/dev/dev/dev/dev/dev/dev/dev/dev/dev/dev/dev/dev/dev/dev/dev/paste/Anyway I can make it work for URLS like http://localhost/dev/contact <--?
Also, can this force redirect take me to http://localhost/main when an extra slash is added? Or remove the extra slashes from the URL so http://localhost/dev//contact - become -> http://localhost/dev/contact automatically?
Thanks in advance
Small edit: I figured out myself that if I use (RewriteRule / [localhost...] [R=301,L] ) double slashes will be redirected to the main index. But still, [localhost...] & [localhost...] or [localhost...] are not redirected.
now it has become about the double slashes before the page name, means the double slash after /dev/
Note (if this make any importance): when this website is done, it will be directly [domain-name-here.org...]
[edited by: Saturn at 1:56 am (utc) on Aug. 2, 2007]