I've been trying for days to generate a file that modifies the url structure.
I have a current url like this
http://localhost/stores/leo
and I need it to stay like this
https://leo.localhost
Use PHP Server XAMP and Larabel
the word "leo" is generated according to the product and it will always change.
How could you generate it?
Thanks!
I have this code that works but the URL changes in the address bar and does not stay with the desired URL.
RewriteEngine On
RewriteBase /
#force https and non-www
RewriteCond %{HTTP_HOST} ^(www\.)(.+) [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]
# profile redirection
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(.*)\.localhost [NC]
RewriteRule (.*) https://localhost/stores/%1/$1 [L]
Related
I am using given below code to redirect to login page,When enter url in address bar e.g.(exmple.com/web/) then redirect to "http://exmple.com/web/login.php" How ?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^exmple.com/web/$
RewriteRule ^$ http://exmple.com/web/login.php [L,R=301]
Try this
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.exmple\.com$
RewriteRule ^$ http://www.exmple.com/web/login.php[L,R=301]
%{HTTP_HOST} variable represents the current domain name without the path segment . Your RewriteCond is invalid because it is trying to match example.com/web/ as domain name which is a non existent domain and the RewriteCond fails.
Change the following condition :
RewriteCond %{HTTP_HOST} ^exmple.com/web$
to
RewriteCond %{HTTP_HOST} ^(www\.)?exmple.com$
You can use the following :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?exmple.com$
RewriteRule ^(web/?)?$ http://exmple.com/web/login.php [L,R=301]
You can also use RedirectMatch in your htaccess to redirect an url to a diffrent location :
RedirectMatch ^/web/?$ http://exmple.com/web/login.php
Clear your browser's cache before testing these solutions.
I have this in my .htaccess file:
# For Friendly URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
I want to redirect the url /sale to the new one /gift-sales So I have added this to the above:
RewriteCond %(THE-REQUEST)^sale$
RewriteRule ^(.*)$ /gift-sales [R=30,L]
In the ModX backend I have, of course, changed the alias to gift-sales, but I cannot seem to get the redirect working. Can anyone point me in the right direction?
try this:
RewriteRule ^/sale http://www.mydomain.com/gift-sales [R=301,L]
I would like to remove the filename from a "subdirectory" URL and just display the subdirectory in the browser URL.
So:
www.domain.com.au/login/public_index.php
becomes:
www.domain.com.au/login/
I have tried various solutions from this site and the internet, but none have worked.
If possible I would like to put the new redirection in the root htaccess file?? and not in the subdirectory htaccess file?
* Just in case other redirections in the htaccess file are in conflict with any new subdirectory redirections, here are the other (and necessary) redirections in the htaccess file that perform important jobs:
#(1) A redirection to remove root level index.php from the url
# Redirect index.php to domain.com.au
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.domain.com.au/ [R=301,L]
#(2)
# Redirect domain.com.au to www.domain.com,au
RewriteCond %{HTTP_HOST} ^domain.com.au [NC]
RewriteRule ^(.*)$ http://domain.com.au/$1 [L,R=301]
#(3)
# Force SSL on login directory
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} login
RewriteRule ^(.*)$ https://www.domain.com.au/$1 [R,L]
Any help would be appreciated as all solutions to add the new subdirectory URL redirect thus far have failed.
Regards,
Peter
You can do something similar to what you did in #(1):
#(4)
# remove public_index.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+)/public_index\.php\ HTTP/
RewriteRule public_index\.php$ http://www.domain.com.au/%1/ [R=301,L]
# internally add it back
RewriteCond %{REQUEST_URI} ^/([^/]+)/?$
RewriteCond %{DOCUMENT_ROOT}/%1/public_index.php -f
RewriteRule ^ /%1/public_index.php [L]
That's for any subdirectory, but if you're only interested in login, that gets easier:
#(4)
# remove public_index.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /login/public_index\.php\ HTTP/
RewriteRule public_index\.php$ https://www.domain.com.au/login/ [R=301,L]
RewriteRule ^/?login/?$ /login/public_index.php [L]
I'm using mod_rewrite to redirect on URLs like: mysite.com/123
RewriteEngine On
RewriteRule ^([0-9]+)$ /n/index.php?id=$1 [L]
This works only for numeric IDs.
How do I make it work for non-numeric IDs while I preventing the redirect from happening when a subdirectory is found?
Change the rewrite rules to this: This should work for both numeric as well as non-numeric IDs preventing the redirect from happening when a subdirectory is found.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([\w\d]+)$ /n/index.php?id=$1 [L]
When visitors go, to say,:
http://website.com/dir/dir2/file.html
My re-write clears the path beyond the base url and redirects them to the home page with www. in the front:
http://www.website.com/
How can I prevent the stripping from occurring and sending visitors to the homepage instead of their requested url? FYI, the URLs in question DO exist.
Thanx!
Include the file/path info on the end of the rewrite like this:
RewriteCond %{HTTP_HOST} !^www\.website\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.website.com/$1 [L,R]
FYI, this is for a Magento site.
In .htaccess, after
#RewriteBase /magento/
After it I placed on their own lines:
RewriteCond %{HTTP_HOST} !^www\.website\.com$ [NC]
RewriteRule ^(.*)$ http://www.website.com/$1 [L,R=301]
And it works. Dad with kids also had it right, just don't know what the second line was for.
Most people need RewriteBase set, so try:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^(?:www\.your-live-domain\.com|staging\.domain\.com)$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule .* http://www.your-live-domain.com/$0 [L,R=301]
Use 301 to make it permanent