I have bunch of folders and files in folder "front". I want to remove "front" from url. I write htacess but it gives 404 error.
RewriteEngine On
RewriteBase /
RewriteRule ^front/(.*)$ /test/$1 [L,NC,R]
I want to rewrite url like this :
http://localhost/test/front/abc/abc.php
to
http://localhost/test/abc/abc
You have it back to front
RewriteEngine On
RewriteBase /
RewriteRule ^test/(.*)$ /test/front/$1 [L,NC,R]
Try adding this to the htaccess file in your document root, preferably above any rules you may already have there:
RewriteEngine On
RewriteRule ^test/(.*)$ /front/$1 [L,R=301]
Related
I have a website with URLs like /product-category/clothing/accessories/?filter_color=yellow now I want to rewrite these kinds of URLs to /index.php/product-category/clothing/accessories/?filter_color=yellow in fact, I want to add a rewrite rule in my htaccess that if the URL contains product-category and does not contain index.php then rewrite the index.php at the beginning of the URL. For this purpose I have developed the following code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} product-category
RewriteRule . /index.php [L]
</IfModule>
But it does not work correctly. First, it adds index.php to all of the URLs and then it adds an extra / when /index.php already exists in the URL
Here is the complete .htaccess file:
htaccess
You may use this rule:
RewriteRule ^product-category/.* /index.php/$0 [L,NC]
am working on making my site urls search engine friendly and for which am rewriting urls with GET parameters and so i have done rewriting but now htaccess is not pointing that url to php file which is suppose to handle the url
my old url
www.domain.com/foo/myfile.php?nid=554
new rewritten url with php
www.domain.com/foo/554-demo-page-title
my current htaccess rules which work for old urls but not for new
Options +FollowSymLinks
RewriteEngine On
#RewriteCond %{SCRIPT_FILENAME} !-d
#RewriteCond %{SCRIPT_FILENAME} !-f
RewriteBase /
RewriteRule ^([0-9]+)-(.*) ./foo/myfile.php?nid=$1 [NC]
so i want to that both old and new urls land on /foo/myfile.php becuase myfile.php can handle both urls incase of old url it rewrite and redirect as new url , i played for few hours with htaccess rules but no success
You can use this rule in site root .htaccess (assuming there is .htaccess inside foo/ directory):
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^foo/(\d+)-.*$ foo/myfile.php [L,QSA,NC]
If you already have /foo/.htaccess then use this rule inside that file:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /foo/
RewriteRule ^(\d+)-.*$ myfile.php [L,QSA]
I'm trying to automatically rewrite a URL to a virtual directory using .htaccess.
My rules are working but not automatically, so for example I have a file called login.php in the root directory and I want to rewrite to to a virtual directory to be like this example.com/login/ instead of example.com/login.php, the below rule works fine for this purpose.
RewriteOptions inherit
RewriteEngine On
RewriteBase /
RewriteRule ^login/$ ./login.php [L,NC]
However, this won't rewrite the login.php file automatically. I need whenever a user requests the login.php file, the rule automatically redirects the user to example.com/login/ and still serve the same content. How could this be achieved?
You will need to a redirect for that:
ewriteOptions inherit
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /login\.php[\s?] [NC]
RewriteRule ^ /login/ [R=301,L]
RewriteRule login/$ ./login.php [L,NC]
i am trying to use .htaccess 301 redirect but its not working
i am using following syntax in my .htaccess file
RewriteRule ^our_services.html http://localhost/site/our-services [R=301,L]
but when i open the page page redirect to
http://localhost/Applications/XAMPP/xamppfiles/htdocs/site/our-services
how to write correct one ?
i want to redirect
our_services.html to our-services
in same domain
Thanks
Can you try relative paths like this:
If in DOCUMENT_ROOT:
RewriteEngine On
RewriteBase /
RewriteRule ^our_services\.html$ /our-services [R=301,L,NC]
If in DOCUMENT_ROOT/site:
RewriteEngine On
RewriteBase /site/
RewriteRule ^our_services\.html$ our-services [R=301,L,NC]
I need to make redirections from a sub-directory to the parent directory.
In other words I have to redirect anything matching
http://exemple.com/portfolio/product1
to :
http://exemple.com/product1
Is there any way to do that with URL REWRITE ?
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 /
RewriteRule ^portfolio/(.*)$ /$1 [L,R=301,NC]
You want to put this into .htaccess inside the directory that you want to be redirrected
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/parent
RewriteRule ^(.*)?$ http://%{HTTP_HOST}/parent