I am interested in URL redirect of any letter case combination of index.html to all lowercase of index.html.
ie:
/foo/bar/INDEX.html
to
/foo/bar/index.html
or
/hello/world/funk/indeX.HTML
to
/hello/word/fund/index.html
I have tried couple regex but no luck. I am interested in Redirect only if there are any uppercase(s) in index.html
/hello/there/index.html
should not redirect anywhere.
I have access to httpd.conf hence I am using RewriteMap lc int:tolower
Try this: (?!index\.html)(?i)index\.html(?-i) it first checks if the string is not index.html, and then matches any string that is case insensitive index.html. Try it here: https://regex101.com/r/GNhAwG/1
Related
I am migrating my blog from a subdirectory to the root of my domain, but I am leaving the admin panel in its current location, as such I need to do a 301 redirect for anything which matches the following path, except the "admin/" subdirectory.
I have the core redirect working with this:
RedirectMatch 301 (^/oldblogpath/)(.*) http://www.example.com/$2
The path I want to exclude from the above is "/oldblogpath/admin/" - please help me understand what I'm missing!
You can use a negative lookahead pattern for this:
RedirectMatch 301 ^/oldblogpath/(?!admin/)(.*) http://www.example.com/$1
(?!admin/) is a negative lookahead condition that fails the match of admin/ appears right after matching starting directory path.
Make sure to clear old browser cache completely before testing this change.
Hi I want to 301 redirect all urls, including the folder name, within the portfolio folder to the homepage.
There are plenty of similar questions/answers, but the ones I could find focused on simply removing the folder from the URL. I don't want that. I need to redirect to a single URL. i.e. remove everything from the source URL and redirect to the homepage.
example of urls I want to redirect
https://example.com/portfolio/
https://example.com/portfolio
https://example.com/portfolio/this-is-a-page
https://example.com/portfolio/this-is-a-another-page
I've used this regex below, but it doesn't work because instead of redirecting to the homepage, it redirects from:
https://example.com/portfolio/this-is-a-page
to
https://example.com/this-is-a-page
I need it to redirect to just https://example.com/ whatever the /portfolio/ child url. What am I doing wrong?
^/?portfolio/(.*)$
https://example.com/$1
You can use:
^/?portfolio(/|$)
https://example.com/
Without $1 , because this $1 is just there to copy the end of the URL
Rewrite with:
RewriteRule ^/?portfolio(/|$) / [NC,R=301,L]
Is it possible to redirect multiple urls by keeping a part of the url or actually removing a part?
For example if I have a site with city guides for multiple cities with the url loremipsum.com/guide-seattle and I change all the urls to loremipsum.com/seattle
So I would want to create a redirect / rewrite rule with maybe regex saying if url is /guide-randomcityname/ then remove guide- and keep randomcityname and redirect to /randomcityname/
A general rule for whatever the city name could be.
Thanks
You can use this redirect rule to remove /guide- from start of your URLs:
RedirectMatch 301 ^/guide-([^/]+/?)$ /$1
I have urls like www.example.com/de/something and I need to redirect to www.example.com everything that starts with /de/.
At the moment I have done this
redirect 301 /de http://example.com
and it redirect all links but just removing /de part and result is www.example.com/something.
How to fix this?
Thanks
redirect directive matchs rest of the uri and appends it to the target, you can use RedirectMatch to redirect a specific uri
redirectMatch 301 ^/de/? http://example.com
If you want /de/ in the target you should have specified so, becasue Redirect will include in the target everything "after" what you have matched.
For a different virtualhost as the destination you want this:
Redirect 301 /de/ http://example.com/de/
or
Redirect 301 /de http://example.com/de
If what you want is redirect inside the same virtualhost /de to /, then use a negative lookahead.
RedirectMatch ^(?!de) http://example.com/
If the context is .htaccess, for virtualhost It would be:
RedirectMatch ^/(?!de) http://example.com/
Note: I use /de/ originally because that's what you describe in your question, and also I match slashes in the target. Both source and target without slashes would be fine too for cases like /desomething or /de/something. In any case, always match slashes or the lack of them.
Note2: Do not use .htaccess to redirect unless you are not the admin of the site. It just complicates things and adds unnecessary overhead since the file/s need to be checked a number of times per hit.
Looking for a regex to redirect (remap) old URL to the Wordpress site efficiently.
The goal is to redirect all the old URL to a new set of URLs without losing the pagerank ( 301 redirect )
/file/Abc_123_ABC_Abc.shtml to be /abc-123-abc-abc
Objectives:
1.remove /file/
2.convert to lowercase
3.replace all _ with - (appears about 2 to 4 times in a URL)
4.remove the extension (both .htm & .shtml)
How to achive the point 3 in htaccess redirect?
Almost identical use-case (the only difference is the lowercase and the folder name):
HTACCESS : RegEx match replace for URL
Best I'm aware, you cannot lowercase using a rewrite rule, so you'll need to rewrite to a redirect handler, and process it from there:
RewriteBase /
RewriteRule ^file/(*+)\.html?$ /file/redirect.php [L,QSA]