Forum Moderators: phranque

Message Too Old, No Replies

[help] .htaccess help .

need backslash in URL

         

ghprod

7:07 am on Oct 24, 2009 (gmt 0)

10+ Year Member



Hi...i have this .htaccess


RewriteEngine On

#untuk url dengan pola www.example.com/page/about-us atau www.example.com/page/about-us/sub-about-us
RewriteRule ^page/(.*)\/(.*)\/? /index.php?page=$1&subpage=$2 [NC]

#404 page
ErrorDocument 403 /index.php?page=404
ErrorDocument 404 /index.php?page=404

RewriteCond %{REQUEST_URI} !^/(index.php).* [NC]
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&]+\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]

And this is my real URL

http://example.com/index.php?page=about-us&subpage=full-story

With .htaccess above, my url turn to

http://example.com/page/about-us/full-story

But when access http://example.com/page/about-us , it will return 404 pages, bcause doesnt have backslash .. so how to give automatic backslash when user access http://example.com/page/about-us => http://example.com/page/about-us/

Please note, i've try this code to add backslash automatic


# If the url is not an existing directory
#RewriteCond %{REQUEST_FILENAME} !-d
# and the URI does not contain a full stop (Example: index.html)
#RewriteCond %{REQUEST_URI} !\.
# and if the URI does not end with a slash
RewriteCond %{REQUEST_URI} !/$
# Rewrite the URI to have a trailing slash
RewriteRule (.+) /$1/ [R=301,L]

It's ok, but when access subpage, everything as broken :(

need help to resolve this :)

thnx b4 and regards

[edited by: engine at 8:46 am (utc) on Oct. 24, 2009]
[edit reason] Please use example.com [/edit]

jdMorgan

1:56 pm on Oct 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



According to your code, a trailing backslash is not required.

So all I can suggest is that you clean up this code and see if it helps:


# Declare custom error documents
ErrorDocument 403 /index.php?page=404
ErrorDocument 404 /index.php?page=404
#
# Enable mod_rewrite rewriting engine
RewriteEngine on
#
# Allow only the listed characters in requested URL-paths
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ /[a-zA-Z0-9.+_/?=&\-]*\ HTTP/
RewriteRule !index\.php$ - [NS,F]
#
# Internally rewrite /page/<page>/<subpage> to /index.php/page=<page>&subpage=<subpage>
RewriteRule ^page/([^/]+)/([^/]+)/?$ /index.php?page=$1&subpage=$2 [NC,L]

Jim

ghprod

1:37 am on Oct 25, 2009 (gmt 0)

10+ Year Member



Hi Jim,

thanks for reply. i've test your code, but when access <page> ex. http://example.com/page/about-us/ return 404. how to fix it?

regards

:)

jdMorgan

2:10 am on Oct 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is no sub-page in that URL. If the subpage can be missing, add another rule to handle that case:

# Internally rewrite /page/<page> to /index.php/page=<page>
RewriteRule ^page/([^/]+)/?$ /index.php?page=$1 [NC,L]

Jim

ghprod

5:52 am on Oct 25, 2009 (gmt 0)

10+ Year Member



wow ... great Jim ... work perfectly :)

thnx a lot ... :D

regards