I am developing a web app in which name of other website are supposed to be given as parameters, am rewriting urls using .htaccess file on my apache web server, this is the code i wrote in my .htaccess file:
RewriteEngine On
RewriteRule ^([a-z0-9\_\-]+(\.)[a-z0-9\_\.\-]+)[^(site.php)] site.php?url=$1
RewriteRule ^([a-z0-9\_\-]+(\.)[a-z0-9\_\.\-]+)[^(site.php)]/ site.php?url=$1
I wrote [^(site.php)]
this because it was passing site.php as parameter as site.php was a match for my regex. This is working the right way but the only problem is that the last character of the parameter is omitted, for example, when am writting:
www.mywebsite.com/google.com
its taking google.co
and omitting the last m
. If am passing google.co.in
, its taking google.co.i
and omitting the n
. What can be the reason for this?
Since you use [^(site.php)]
(and it doesn't means what you think), it will match the last character of your url. You should use a RewriteCond, you can try :
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9\_\-]+(\.)[a-z0-9\_\.\-]+)/?$ site.php?url=$1
Wich means : do not rewrite for existing file or directory
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.