I need to rewrite url only one directory named gallery.
I would like to have abc.com/photos/gallery/picture/ instead of abc.com/photos/gallery/picture.php
.htaccess
index.php
/photos
/gallery
index.php
picture.php
functions.php
/videos
Here is my code to .htaccess but it doesn't work.
RewriteEngine on
RewriteRule ^/[.*]/?$ photos/gallery/$1.php#{QUERY_STRING} [NC,L]
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension
# To externally redirect /gallery/foo.php to /gallery/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(/+gallery/[^.]+)\.php [NC]
RewriteRule ^ %1 [R=302,L]
## To internally forward /gallery/foo to /gallery/foo.php
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(gallery/.*?)/?$ $1.php [L,NC]
Related
When I access my site via www.domain.com/index.php or www.domain.com/index.html, it needs to redirect to www.domain.com for SEO purposes.
How do I configure this in .htaccess?
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /(index)|(home)(..{3,4})?$ [NC]
RewriteRule ^([^/]+/)+ http://www.example.com/$1? [R=301,L]
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
DirectoryIndex index.html index.php
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteRule ^index\.(html?|php)$ / [L,R=301,NC]
I am using the following code in .htaccess file
DirectoryIndex home.php
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^$ - [L]
RewriteRule ^/?([^\./]*)[:;,\.]*$ $1.php
RewriteRule ^([a-zA-Z0-9_,-]+)/([0-9]*)$ listing.php?business=$2
This code hides the .php extension of the PHP files in the root folder only, But I want to apply it to the PHP files in all subfolders.
I also want to deny access using the original URL , that is the URL includes the .php extension.
I also want the third rule should be worked.
Replace your code with this:
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9_,-]+)/([0-9]+)$ listing.php?business=$2 [L,QSA]
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php[\s\?] [NC]
RewriteRule ^ - [F]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]
if user hit my_website.com then he should redirect to my_website.com/abc but if he hits my_website.com/xyz then he can visit normally.
How can i do this using .htacess file
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^my_website\.com$ [NC]
Rewriterule ^$ /abc [L,R=302]
Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.
Try with this
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://my_website.com/abc [L,R=301]
I have content from a different server on a subdomain that I would like to use as a subdirectory. Everything from sub.domain.com should be accessible to domain.com/sub I would like sub folders to work as well ex: sub.domain.com/about should be domain.com/sub/about
Here's my current .htaccess contents
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(sorry).* - [NC,L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Any help appreciated. Thanks!
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^ http://domain.com/sub%{REQUEST_URI} [R=301,L,NE]
I am stuck with .htaccess modification, need a little help.
First off, here is whats inside my htaccess.
RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php [nc]
For example, I created the file named test.php and uploaded to my server.
I want my server to behave like this.
http://example.com/test/test.html -> http://example.com/test/test.html(as it is)
http://example.com/test/test.php -> http://example.com/test/test.html
but with the .htaccess I have right now,
I still have both .php and .html which may be considered as file duplication by search engine crawler like Google robot (isn't it?).
Any help appreciated.
try this .htaccess code
# Enable Rewrite Engine
RewriteEngine on
#Create friendly URL
RewriteRule ^test/(.*)\.html$ test/$1\.php [L]
OR
RewriteCond %{REQUEST_URI} ^(.*)\.php$
RewriteRule ^(.*) /$1.html [L]
OR
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## .php to .html
# To externally redirect /test/test.php to /test/test.html
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1.html [R,L,NC]
This is a configuration file of apache '.htaccess' if you still want to configure then change
RewriteEngine on
I hope this work
You may try this in one .htaccess file in root directory:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !\.html [NC]
RewriteRule ^([^/]+)/([^.]+)\.php /$1/$2.html [R=301,NC,L]
For silent mapping, replace [R=301,NC,L] with [NC,L]