301 Redirect specific page with ModX Evo - url

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]

Related

Change url estructure htacesss

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]

How to redirect page by using .htaccess

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.

Hidden Space in URL

When I go to http://sweatingthebigstuff.com/lending-club-loans-to-avoid/, I get a 404 page. But when I hit backspace twice, it deletes the / but not the d so there's a hidden space there. Once I delete it, it works.
How is there a hidden space in my URL and can I do something to detect and delete it in the .htaccess file? Otherwise every redirection I add has to be one of each.
EDIT:
Here's what I think may be relevant from the .htaccess file:
RewriteCond %{REQUEST_URI} !\.[^./]+$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://sweatingthebigstuff.com/$1/ [R=301,L]
RedirectMatch 301 ^/[0-9]{4}/[0-9]{2}/[0-9]{2}/(.+)$ /$1
It actually looks like this: http://sweatingthebigstuff.com%E2%80%8B/lending-club-loans-to-avoid%E2%80%8B/
Try changing
RewriteCond %{REQUEST_URI} !\.[^./]+$
RewriteCond %{REQUEST_URI} !(.*)/$
to
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

.htaccess non-www to www URL Redirect Erases any URL path beyond base url

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

Redirect "mydomain.com/user" to "mydomain.com/name.php?id=user"

I think I can use the .htaccess file for this, but I've looked it up and not found anything useful. What I want to do is have my site redirect to a php page when a user types their username in the URL like:
example.com/username
And have it be the same as a PHP page like:
example.com/name.php?id=username
I'd like it to display as example.com/username even after it redirects, but it is not necessary. Any ideas?
You can use mod_rewrite to transparently rewrite your URLs on the server.
Assuming that you'd only have usernames following your domain, something like this would do what you want:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .+ name.php?id=$0
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+) users.php?user=$1 [L]
I think that will work.
The Apache mod_rewrite guide is here
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
You probably want Apache's mod_rewrite.

Resources