0

I would like to find a RewriteRule that does this :

mysite.net/jqMAS/ or mysite.net/jqMAS => mysite.net/index.php?id=jqMAS

I used such a .htaccess file :

RewriteEngine On RewriteRule ^(.*) index.php?id=$1 

But unfortunately, it doesn't work (maybe mysite.net/index.php is itself redirected to mysite.net/index.php?index.php, etc. ?) : calling mysite.net/jqMAS produces a 500 Internal Server Error.

What RewriteRule should we use to do such URL shortening ?


Here is what the index.php page (I didn't mention the headers) looks like :

 <body> Bonjour <?php echo $_GET['id']; ?> </body> 
5
  • it doesn't work what doesn't work? Commented Sep 20, 2014 at 23:47
  • @Qix : calling mysite.net/jqMAS produces a 500 Internal Server Error. Commented Sep 20, 2014 at 23:52
  • 2
    @Basj What does apache error log says? Commented Sep 20, 2014 at 23:58
  • On Linux look at /var/logs/apache/error.log Commented Sep 21, 2014 at 1:35
  • @RahilWazir I don't have access to error.log. I have a shared 1&1 hosting. The only logs I have are : access.log.38.7 and mail.log.38.7 (38 is for the week number) Commented Sep 21, 2014 at 8:59

3 Answers 3

2

Try the following your .htaccess file, as it is the setup successfully used on my own website.

# Enable the rewriting engine. RewriteEngine On # Change requests for a shorter URL # Requires one or more characters to follow the domain name to be redirected RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?id=$1 [L] 
Sign up to request clarification or add additional context in comments.

Comments

1

There are 2 htaccess files: Keep your htaccess file within application folder as: Deny from all.

and paste following code to your htaccess file outside the application folder:

RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] 

It is working perfect for me.

4 Comments

Thanks! I still get a 500 Internal Server Error... I don't know why. What about the 2 .htaccess files ? I only have one. Can you give some details about "Deny from all"? Do you speak about file permissions? What file permissions should I set for .htaccess and for index.php ? 644 ?
are you getting this error on localhost or on server link??
I don't know the reason. I solved by setting all files to permission 644 and finally used : <IfModule mod_rewrite.c>, RewriteEngine On, RewriteBase /, RewriteCond %{REQUEST_FILENAME} !-f, RewriteCond %{REQUEST_FILENAME} !-d, RewriteRule ^(.*)$ /index.php?id=$1 [L], </IfModule>
How will this rule populate $_GET['id']?
1

You need RewriteCond to stop rewriting for real files and directories:

RewriteEngine On # if request is not for a directory RewriteCond %{REQUEST_FILENAME} !-d # if request is not for a file RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.+)$ index.php?id=$1 [L,QSA] 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.