Reputation: 16495
I have WAMP installed, and a project at in E:/wamp/www/project/index.php
Links from index.php
redirect to show.php
I am using the below .htaccess
script to be able to make URL in show.php
appear as /article-title
instead of what it normally does i.e show.php?id=xxx
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule (.*)$ show.php?id=$1 [QSA,L]
But, the above .htaccess
file which is found in project/
along side the index/show page does not seem to work. It does not even show me the project folder, when I go to www/
I don't know where the problem is, and rewrite-module is on
Upvotes: 0
Views: 77
Reputation: 19528
Given that your article URL is like this:
http://localhost/project/1122-some-title-comes-here
You can use this rule:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^project/(\d+)-([\w-]+)/?$ /project/show.php?id=$1 [QSA,L]
If you want your articles from the root folder like this:
http://localhost/1122-some-title-comes-here
You can change the above to:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(\d+)-([\w-]+)/?$ /project/show.php?id=$1 [QSA,L]
The above conditions means, if folder, files and symbolic links are false, rewrite it.
The rule itself ^(\d+)-([\w-]+)/?$
if it start with digits and a dash and contains additional alphanumeric characters and dash and end or not with /
internally redirect to:
/project/show.php?id=$1
The $1
means to pass the result of the parenthesis from the rule to the id which is (\d+)
which in our URL example would mean the number 1122
.
Upvotes: 1
Reputation: 2243
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html "The RewriteBase directive specifies the URL prefix to be used for per-directory (htaccess) RewriteRule directives that substitute a relative path."
Upvotes: 0