I am not facing another problem with my mod_rewrite, first, time is my .htaccess file:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^news/([0-9]+)/?$ /news?id=$1 [L,QSA]
RewriteRule ^contact/([0-9]+)/?$ /contact?do=$1 [L,QSA]
RewriteRule ^account/([a-zA-Z]+)/?$ /account?action=$1 [L,QSA]
RewriteRule ^admin/([a-zA-Z]+)/?$ /admin?action=$1 [L,QSA]
RewriteRule ^login/([a-zA-Z]+)/?$ /login?action=$1 [L,QSA]
RewriteRule ^register/([a-zA-Z]+)/?$ /register?action=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L] <- This line doesn't work
RewriteRule ^([\w\d~%.:_\-]+)$ index.php?page=$1 [L,QSA]
All lines are working, beside the RewriteRule ^([^.]+)$ $1.php [NC,L]
and when I use this line, all other rules gets interrupted.
What am I doing wrong?
You need to use L flag in your problematic rule.
For removing the .php extension this is better rule:
Options +FollowSymlinks -MultiViews
RewriteEngine on
## If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
## If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
## If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
## don't do anything
RewriteRule ^ - [L]
RewriteRule ^news/([0-9]+)/?$ /news?id=$1 [L,QSA]
RewriteRule ^contact/([0-9]+)/?$ /contact?do=$1 [L,QSA]
RewriteRule ^account/([a-zA-Z]+)/?$ /account?action=$1 [L,QSA]
RewriteRule ^admin/([a-zA-Z]+)/?$ /admin?action=$1 [L,QSA]
RewriteRule ^login/([a-zA-Z]+)/?$ /login?action=$1 [L,QSA]
RewriteRule ^register/([a-zA-Z]+)/?$ /register?action=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteRule ^(.+?)/?$ index.php?page=$1 [L,QSA]
Try something like
#Preventing loop
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]
RewriteCond %{REQUEST_URI} !^.+\.php.*$
RewriteRule .* - [L]
Put this after RewriteRule ^register/([a-zA-Z]+)/?$ /register?action=$1 [L,QSA]
Related
I have three four pages
page.php?s=defaultpage
page.php?p=defaultpage
blog.php?post=defaultpage
projects.php?view=defaultpage
I have this exisiting URL redirect code snippet. The fourth page is new, and I would like to write a condition for that to only show projects/defaultpage
How do I achieve this with the existing Rewrite condition.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Options -MultiViews
RewriteEngine On
RewriteBase /Renu/
RewriteCond %{THE_REQUEST} /page\.php\?([a-z])=([^&\s]+)
RewriteRule ^ %1/%2? [R=302,NE,L]
RewriteCond %{THE_REQUEST} /blog\.php\?post=([^&\s]+) [NC]
RewriteRule ^ blog/%1? [R=302,NE,L]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteRule ^blog/([^/]+)/?$ blog.php?post=$1 [L,NC,QSA]
RewriteRule ^([a-z])/([^/.]+)/?$ page.php?$1=$2 [L,QSA]
Just add this line, before the last line:
RewriteRule ^projects/([^/]+)/?$ project.php?view=$1 [L,NC,QSA]
RewriteRule (.)/(.)/(.*)/$ /?view=$1&$2=$3
in php with get is :
example.com/?view=profile&nick=NickName
with .htaccess
example.com/profile/NickName/
I am facing problem with mod_rewrite ^(.+)$ /article.php?pname=$1 [L,QSA] is working fine but after that other RewriteRule dont work i dont know why ... here is my code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /article.php?pname=$1 [L,QSA]
RewriteRule ^category/(.*)$ /cat.php?name=$1 [QSA,L]
ErrorDocument 404 /index.php
</IfModule>
If i remove RewriteRule ^(.+)$ /article.php?pname=$1 [L,QSA] other RewriteRule works but it dont work with this, how can both work together ?
Please help
Keep your .htaccess like this:
ErrorDocument 404 /index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^category/(.*)$ cat.php?name=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ article.php?pname=$1 [L,QSA]
</IfModule>
Simple change order, from:
RewriteRule ^(.+)$ /article.php?pname=$1 [L,QSA]
RewriteRule ^category/(.*)$ /cat.php?name=$1 [QSA,L]
To:
RewriteRule ^category/(.*)$ /cat.php?name=$1 [QSA,L]
RewriteRule ^(.+)$ /article.php?pname=$1 [L,QSA]
Because (.+) will rewrite everithing including cat.php. So when you are trying to access cat.php?name=someName you will get /article.php?pname=cat.php%3Fname%3DsomeName.
You should do following:
RewriteCond $1 !^(cat\.php|someFolder|robots\.txt)
RewriteRule ^(.+)$ /article.php?pname=$1 [L,QSA]
Or even this:
RewriteCond %{DOCUMENT_ROOT} !-f
RewriteRule !(cat\.php|someFolder|robots\.txt)$ /article.php?pname=$1 [QSA,L]
robots.txt should not to be rewrited.
When user types:
www.domain.com/standard/Public/Modules/home.php or
www.domain.com/standard/Public/Modules/contacts.php
(or anything that follows the same pattern)
I want the URL to be displayed like this:
www.domain.com/home
www.domain.com/contacts
...
My current .htaccess:
RewriteEngine on
RewriteRule ^home.php/?$ standard/Public/Modules/home.php [NC,L]
RewriteRule ^contacts.php/?$ standard/Public/Modules/contacts.php [NC,L]
You need to have this in your root .htaccess:
RewriteEngine on
RewriteCond %{THE_REQUEST} /standard/Public/Modules/login\.php [NC]
RewriteRule ^standard/Public/Modules/login\.php$ /home [L,NC,R=301]
RewriteCond %{THE_REQUEST} /standard/Public/Modules/logout\.php [NC]
RewriteRule ^standard/Public/Modules/logout\.php$ /contacts [L,NC,R=301]
RewriteRule ^home/?$ /standard/Public/Modules/login.php [NC,L]
RewriteRule ^contacts/?$ /standard/Public/Modules/logout.php [NC,L]
I use this, no need to individually set rewrites for pages
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
For example
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)-product(.*).html$ /products/view/$2 [L]
RewriteRule ^(.*)-cat(.*).html$ /products/listing/$2 [L]
RewriteRule ^products.html$ /products/listing/ [L]
RewriteRule ^bioproducts.html$ /products/bio_listing/ [L]
RewriteRule ^aboutus.html$ /static/index/15 [L]
RewriteRule ^contacts.html$ /static/contacts [L]
RewriteRule ^(.*)-partners(.*).html /partners/index/$2 [L]
</IfModule>
i have a rewrite rule.
RewriteRule ^pages/(.+)$ info_pages.php?page_url=$1 [L]
this was working well Before.
my url like this but at localhost
http://dressgirls.com/demo2/pages/contact-us.html
this pointing to
http://dressgirls.com/demo2/info_pages.php
when i use this
echo $_GET['page_url'];
it gives me. contact-us.html/contact-us.html/contact-us.html
it should give contact-us.html one time only.
do you have idea what is wrong here.?
This is full code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^pages/(.+)$ info_pages.php?page_url=$1 [L]
RewriteRule ^reviews/(.+)$ edit_review.php?review_id=$1 [L]
RewriteRule ^deals/(.+)$ category.php [L]
RewriteRule ^city/(.+)$ location_deals.php [L]
#RewriteCond %{REQUEST_FILENAME} =-f
#RewriteRule ^(.*)\.php$ $1.html [NC,L]
#RewriteRule ^(.*)\.html$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} ^(.*)\.html$
RewriteCond %1.php -f
RewriteRule ^(.*)\.html$ $1.php [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ deal-detail-page.php [QSA,L]
</IfModule>
Thanks.
Change code to:
RewriteBase http://dressgirls.com/
RewriteRule ^pages/(.+)$ info_pages.php?page_url=$1 [L]
and try.
I have such .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule (.*)/sites/([^a-zA-Z][0-9_/]*$) $1.php?sites=$2 [L]
RewriteRule (.*)/sites/([0-9_/]*)/(.*) $3 [L]
RewriteRule (.*)/sites/(.*) $2 [L]
RewriteRule tags_xml/(.*).xml tags/display_xml.php?tag=$1 [L]
RewriteRule news_xml/(.*).xml rss.php?site=$1 [L]
RewriteRule tags/([ÄĂ“ĹŚĄŻŹĆĹęółśążźćńa-zA-Z0-9%\ ]*)/([^a-zA-Z][0-9_/]*$) tags/display.php?tag=$1&page=$2 [L]
RewriteRule tags/([ÄĂ“ĹŚĄŻŹĆĹęółśążźćńa-zA-Z0-9%\ ]+) tags/display.php?tag=$1 [L]
RewriteRule news/([0-9]*)/([0-9]*)/([^a-zA-Z][0-9]*)/(.*).html$ kom.php?id_b=$1&id_n=$2&kom_page=$3 [L]
RewriteRule news/([0-9]*)/([0-9]*)/(.*).html$ kom.php?id_b=$1&id_n=$2 [L]
RewriteRule news/([0-9]*)/([0-9]*)/([^a-zA-Z][0-9]*)/(.*) $4 [L]
RewriteRule news/([0-9]*)/([0-9]*)/(.*) $3 [L]
RewriteCond %{THE_REQUEST} ^.*index.php.*
Now when I enter
www.domain.com/file
instead of
www.domain.com/file.php
it works ok, but when I enter
www.domain.com/tags/Bank
I got no such tag found error. Also other scripts in this folder just display "no such tag found".
The previous working code was:
RewriteEngine On
RewriteBase /
RewriteRule (.*)/sites/([^a-zA-Z][0-9_/]*$) $1.php?sites=$2 [L]
RewriteRule (.*)/sites/([0-9_/]*)/(.*) $3 [L]
RewriteRule (.*)/sites/(.*) $2 [L]
RewriteRule tags_xml/(.*).xml tags/display_xml.php?tag=$1 [L]
RewriteRule news_xml/(.*).xml rss.php?site=$1 [L]
RewriteRule tags/([ĘÓŁŚĄŻŹĆŃęółśążźćńa-zA-Z0-9%\ ]*)/([^a-zA-Z][0-9_/]*$) tags/display.php?tag=$1&page=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule tags/([ĘÓŁŚĄŻŹĆŃęółśążźćńa-zA-Z0-9%\ ]+) tags/display.php?tag=$1 [L]
RewriteRule news/([0-9]*)/([0-9]*)/([^a-zA-Z][0-9]*)/(.*).html$ kom.php?id_b=$1&id_n=$2&kom_page=$3 [L]
RewriteRule news/([0-9]*)/([0-9]*)/(.*).html$ kom.php?id_b=$1&id_n=$2 [L]
RewriteRule news/([0-9]*)/([0-9]*)/([^a-zA-Z][0-9]*)/(.*) $4 [L]
RewriteRule news/([0-9]*)/([0-9]*)/(.*) $3 [L]
RewriteCond %{THE_REQUEST} ^.*index.php.*
Update:
OK, after reading through your htaccess again, I notice that you use the following:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
On some systems this will point relative to your filesystem, so maybe adding DOCUMENT_ROOT will work for you. Like so:
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
The solution was to just add at the end:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]