I am trying to create seo url for my website. Actually i am aware of how to write code through htaccess. i found many tutorials but not helps me.i also write a code inside but not working. to remove php extension first code works successfully.while writing next code for seo url its load my whole page again in body. please help me
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^**photos**/([a-zA-Z0-9_-]*)/([a-zA-Z0-9_-]*) /photos.php?category=$1&page=$2 [NC,L]
No need of multiple "RewriteEngine On" statement. Did you try with below lines?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^**photos**/([a-zA-Z0-9_-]*)/([a-zA-Z0-9_-]*) /photos.php?category=$1&page=$2 [NC,L]
Options +FollowSymLinks
Related
I attempted to create a little bit of htaccess which alters a URL from something like
http://localhost/website/page.php?id=_abc-123
to
http://localhost/website/page/_abc-123
It works for the most part, in that I can visit the page without having trouble locating scripts and CSS files. However, if I try to echo out $_GET["id"], instead of getting _abc-123, I will get _abc-123.php.
This is what I have so far within my htaccess file:
Options +FollowSymLinks
# remove extensions
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# movie page
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^page/([^/]*)$ page.php?id=$1 [L]
All help is appreciated,
Thanks.
Test movie page first, and test if file with .php exists:
Options +FollowSymLinks -MultiViews
RewriteEngine On
# movie page
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^page/([^/]*)$ page.php?id=$1 [L]
# remove extensions
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^.]+)/?$ $1.php [L]
First of all, if you are not sure where your error lies, you can try online tools for .htaccess like htaccess.mwl.be.
Obviously your first RewriteRule contitions are met, which results in your "error".
With the help of this tool and some knowledge about how regex work, we can fix your .htaccess to this:
Options +FollowSymLinks
# remove extensions
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC]
# movie page
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^page/([^/]*)$ page.php?id=$1 [L]
The only thing I changed is removing the "L" flag from your first RewriteRule, because its RewriteCond is met but we need it to go through the second RewriteRule.
For more information about the L-flag have a look at the documentation.
I wants my website URLs in this format:
http://www.myglobeon.com/shop/Heeta_Colection_2023
The .htaccess file is below, please help.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^shop/([^\.]+)$ shop.php?store=$1 [NC,L]
I have url like
http://example.com/index.php/allmodels/Samsung-mobiles_80
and i want to convert into
http://example.com/index.php/allmodels?st=Samsung-mobiles_80
I am using following code
Options -Indexes
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^allmodels/(.*)$ /allmodels?st=$1 [NC,L]
but this code is not working.
All the setting is correct I have tested and htaccess is working.
When i used following code that is working but above given code is not working.
Options -Indexes
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [NC,L]
This is Code,which is use for removing file extension. I want to remove Directory name as well.what to add in this code.
Structure of project= airgle is a index page contains navigation pages.
now,my url is
localhost/demo/airgle/navigation1
i wants localhost/demo/navigation1
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Hope this code help you,
RewriteEngine On
RewriteCond %{HTTP_HOST} ^localhost/airgle/navigation1/file_name$
RewriteRule ^$ http://localhost/navigation1/file_name [L,R=301]
You can use this rule in /demo/.htaccess:
RewriteEngine On
RewriteBase /demo/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?! airgle/).+?)/?$ airgle/ [L,NC]
I am trying to do some rewrites with my .htaccess file
All I am trying to do is rewrite the url:
www.example.com/book.php?course=#WHATEVERSLUG
to
www.example.com/course/#WHATEVERSLUG
WHICH I HAVE SUCCESSFULLY BEEN USING THE CODE BELOW FOR A WHILE NOW WITH NO ERRORS
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^course\/([^/\.]+)/?$ book.php?course=$1 [L]
Then, I tried adding another rewrite mod, below:
RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]
to shorten my urls by removing the .php extensions, and remove the traling slashes and it appears that they do not mix well for some reason. I am not very good with .Htaccess, so any help will be possitive.
Or if someone has another suggestion to rewrite:
www.example.com/book.php?course=#WHATEVERSLUG
to
www.example.com/course/#WHATEVERSLUG
And
Rewrite .php files to remove extenstions and traling slashes..
it'd be so greately appreciated. Thank you in advance.
Figured it out!:
w/ a little a help from: Multiple conflicting htaccess RewriteRules
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^course\/([^/\.]+)/?$ ./book.php?course=$1