I'm so newbie in apache, so it's a basic question but I couldn't solve this using another questions or links.
I tried to change my URL
using .htaccess
and I had two purposes;
- hide
.php
extension - change some queryString from
somefile.php?id=bar
tosomefile/id/bar
whichbar
is a number or mixed string likeT51-3
.
My queryString ishttp://localhost/payment/theme/ticket?id=770314
that I want change it tohttp://localhost/payment/theme/ticket/id/770314
or
http://localhost/payment/theme/ticket/770314
I found this code:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f [NC]
RewriteRule ^ %{REQUEST_URI}.php [L]
in stackoverflow.com/this_question
This was working nice but didn't solve my second issue.
So, I searched for a while in this site and others and did find some sample codes like this one :
RewriteRule ^([a-zA-Z0-9_-]+)-([0-9]+)$ ticket.php?id=$2
or
RewriteRule ^(.*)$ /ticket.php?url=$1 [L]
and etc...
but none of these didn't work for me.
Some of them will make the server done and some don't have any affect at all.
Would you please guide me to right way...
I looked at these questions:
htaccess rewrite for query string
how to change query string parameters with name using .htaccess?
How can I use .htaccess to hide .php URL extensions?
And these links:
http://simonecarletti.com/blog/2009/01/apache-query-string-redirects/
https://wiki.apache.org/httpd/RewriteQueryString
UPDATE :
This is my site strucure:
There is an htaccess for important folders, like, forms
, db
, classes
etc...
All my site pages are in the theme
folder, as you can see in the picture.
In the root htaccess, there's just two lines that auto start sessions.
And I added your code to theme's htaccess.
Thanks in Advance