0

I've a page like this link: www.mysite/lab/index.php?pagina=blablabla

I used .htaccess with this settings:

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^([A-Za-Z0-9]+)$ ./index.php?pagina=$1 [QSA,L] 

If I go on www.mysite/lab/blablabla I don't see my page but I've error page not found

I've page in www.mysite/lab/ and other 3 folders, can I use ELSE IF in .htaccess?

10
  • What does not work exactly? What error do you get? The only fault I see right now, is that there are 2 equality signs in the RewriteRule, but it should rewrite the request... Commented Jan 27, 2015 at 10:39
  • "It doesn't work" as in how exactly it doesn't work? Is the double equal sign at ?pagina==$1 intentional? Commented Jan 27, 2015 at 10:40
  • It's a mistake to write here! In my file there is only one! Commented Jan 27, 2015 at 10:42
  • Error is that if I go on www.mysite/lab/blablabla I don't see my page Commented Jan 27, 2015 at 10:42
  • Do you want to have only one htaccess file to handle those 4 folders ? In that case, your htaccess would be located in root folder. Otherwise, you can have 4 different htaccess (one for each folder) with almost the same code Commented Jan 27, 2015 at 11:02

3 Answers 3

1

Since you want only one htaccess to handle all your concerned folders, you can put this code in your htaccess (which has to be in root folder)

RewriteEngine On RewriteBase /mysite/ RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(lab|blog|faq|presentazione|feed|editori)/([^/]+)$ $1/index.php?pagina=$2 [L] 
Sign up to request clarification or add additional context in comments.

12 Comments

I put my .htaccess in root folder?
Yes in the document root folder (where your domain is pointing to)
I put in my root folder and in localhost I can't see new permalink :( I see my site from 127.0.0.1/mysite/lab/index.php?pagina=blablabla and if i go in 127.0.0.1/mysite/lab/blablabla tell me page not found
That's because you are in a subfolder mysite. I edited my answer taking your comment into consideration. But now, you have to put the htaccess in mysite folder instead of root folder
Did you enable mod_rewrite and allow htaccess in your apache configuration ? Did you replace mysite (RewriteBase line) by your real subfolder name ?
|
0

Your rewrite rule is taking the whole request path and using it as a parameter for $1. You only need to capture content right of the last slash, not the whole path.

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule /lab/([A-Za-z0-9]+)$ index.php?pagina=$1 [QSA,L] 

You can additionally use RewriteBase to specify the base for your rewrites which essentially allows you to skip the /lab/ part.

RewriteEngine On RewriteBase /lab/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ([A-Za-z0-9]+)$ index.php?pagina=$1 [QSA,L] 

3 Comments

With this i've a 500 Internal Server Error.
I've page to rewrite in myste/lab and in other 3 folders..can I use ELSE IF in htaccess?
Try editing your rewrite rule so that the second range in the group contains only small letters. In other words change [A-Za-Z0-9] to [A-Za-z0-9] If that doesn't work check the web server logs to see what caused the error.
0

You're denying the / from the regexp. You either need to do what holodoc said, or modify the regexp to

^([A-Za-Z0-9/]+)$

1 Comment

That's a good solution for the problem. Anyway, you don't need to escape the slash

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.