I try to make a custom link like:
mysite.com/users/test
I have the following code in my .htaccess file:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9\_\-]+)$ index.php?h=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([A-Za-z0-9\_\-]+)\/(.*)$ index.php?h=$1&p=$2 [QSA,L]
My problem is: with one "/something" is working, the index.php loads correctly but with "/something/test" I'm gettin a Uncaught SyntaxError: Unexpected token <.
Thankyou.
I think the "\/
" in the following is incorrect.
RewriteRule ^([A-Za-z0-9\_\-]+)\/(.*)$ index.php?h=$1&p=$2 [QSA,L]
I think that should be: RewriteRule ^([A-Za-z0-9\_\-]+)/(.*)$ index.php?h=$1&p=$2 [QSA,L]
One thing to note with your definitions is that there is no RewriteBase
directive specified and the index.php
portion would usually be preceded by a leading slash - which leads to:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9\_\-]+)$ /index.php?h=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([A-Za-z0-9\_\-]+)/(.*)(/?)$ /index.php?h=$1&p=$2 [QSA,L]
Tested this using the url https://localhost/something/somethingelse/blahblah/?page=1
which showed the following GET variables:-
Array
(
[h] => something
[p] => somethingelse/blahblah
[page] => 1
)