-1

I'm trying to perform a URL Rewrite but giving me a 500 Internal Server Error

I have an index.php file that can take a parameter which I called cmd so the URL should look like:

http://localhost/some_folder/index.php?cmd=some_parameter

What I'm trying to achieve is allowing users to just type any of the following:

http://localhost/some_folder/some_parameter

OR

http://localhost/some_folder/index/some_parameter

Here is my .htaccess file:

RewriteEngine On    # Turn on the rewriting engine
RewriteRule    ^index.php/?$    index.php?cmd=shifts    [NC,L]

I also tried:

Options +FollowSymLinks
RewriteEngine on

RewriteRule /cmd/(.*)/ index.php?cmd=$1

I don't know what I am doing wrong here!

sikas
  • 5,435
  • 28
  • 75
  • 120
  • 1
    My tummy tells me that the first `.htaccess` snippet seems to be creating an infinite loop of rewrites. For instance, if you request `/index.php?cmd=test`, it will be rewritten to `/index.php?cmd=shifts`... and as the rule still applies, it'll be rewritten *again* to `/index.php?cmd=shifts`. This goes on until the limit of internal redirects is reached. – Mel Kicchi Dec 26 '13 at 20:50
  • 2
    There is an apache error log that will tell you what the problem is. In ubuntu it is usually at `/var/log/apache2/error.log` – Jonathan Kuhn Dec 26 '13 at 21:00
  • @JonathanKuhn I found this error `Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration` – sikas Dec 26 '13 at 23:45
  • it is shown as an alert – sikas Dec 26 '13 at 23:45
  • In my answer below, I have managed to somehow do it. But still on a single page, I'm getting an error!! – sikas Dec 27 '13 at 12:49

2 Answers2

1

I found this error Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

You need to load mod_rewrite. See this answer for details for how to fix.

Community
  • 1
  • 1
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • Ok, I loaded the module and now I'm not getting any errors .. But the rewriting is not working!! – sikas Dec 27 '13 at 10:58
  • Can you check my answer below? It still gives me error with the rootFolder only!! – sikas Dec 27 '13 at 12:46
0

After lots of searching on the internet and especially stackoverflow, I reached a solution (not what I wanted, but it is working for now until I find another one that suits my needs better.

Here is the .htaccess that I'm using at the moment (actually I'm using 2 files as each folder/sub-folder got different parameters):

Options +FollowSymLinks
RewriteEngine on
RewriteBase /rootFolder # In the sub-folder I type /rootFolder/subFolder
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule /cmd/(.*)/ index.php?R=$1 # In the sub-folder I type index.php?cmd=$1

Now I access using the URL http://localhost/rootFolder/index/R/xxx-1234 and http://localhost/rootFolder/admin/index/cmd/xxx

What I need to do is remove the index portion of the URL.

sikas
  • 5,435
  • 28
  • 75
  • 120