Matching a URL in htaccess - .htaccess

I have this htaccess file:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+:/.)$ result.php?u=$1
RewriteRule ^([a-zA-Z0-9]+:/.)/$ result.php?u=$1
And what i'm trying to do is, rewrite http://example.com/http://google.com to http://example.com/result.php?u=http://google.com but I just get a "The requested URL was not found on this server"

Try this:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9:/\.]+)$ http://example.com/result.php?u=$1

Related

URL Rewrite xml to rss

I have a feed.xml file containing my RSS feed and I'd like to rewrite the url example.com/feed.xml to example.com/feed.rss.
I've tried with this code:
RewriteEngine On
RewriteBase /
RewriteRule ^feed.xml$ feed.rss [L]
But it doesn't work. When I access the feed.xml, it displays the feed and when I access the feed.rss I have an Error 404.
I know that is possible but I think something is wrong with my code.
Just swap the pattern and substitution in your RewriteRule directive:
RewriteEngine On
RewriteBase /
RewriteRule ^feed\.rss$ /feed.xml [L]

.htaccess Rewrite rule not working - wildcards

Simple url rewrite:
Url is e.g.
http://mydm.com/search/this/could/be/anything
The only critical word here is search - I want this to resolve to:
http://mydm.com/pages/search.html
This is what I'm trying but I get a 404 error:
RewriteEngine On
RewriteRule ^search/([^/])/([^/])/([^/])/([^/])$ /pages/search.html
Am I doing the wildcard matching wrong?
Try with:
RewriteEngine On
RewriteRule ^search/ /pages/search.html [NC,L]

How to rewrite url with space in it with .htaccess

If 'localhost/a/something' is the url, the .htaccess rewrites it to 'localhost/a/1.php?food=something'
If I type in 'localhost/a/something something' it gives me a 404 error.
My current .htaccess:
RewriteEngine on
RewriteBase /a/
RewriteRule ^([A-z]+)$ 1.php?food=$1 [L]
How can I 'localhost/a/something something' to 'localhost/a/1.php?food=something+something'?
Please have a look at:
How to redirect %20 or White space automatically to + or - with htaccess?
This seems to do what you are trying to do...
Try this rule in your .htaccess:
RewriteRule ^article/with\ 1.php$ /food/1.php [R=301,L]

change url and access to file by htacess

My real url is:
/a/bc/de/test/1.jpg
I want access to my file by this url without redirect:
/abcde/test/1.jpg
How can i do that?
This is pretty strange rewrite rule but you can try this rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^([a-z])([a-z]{2})([a-z]{2})/(test/.+)$ /$1/$2/$3/$4 [L,NC]
Tanx for help, this is correct:
RewriteRule ^([0-9a-f]{1})([0-9a-f]{2})([0-9a-f]{2})/([0-9a-z-]{1,})/(.+)$ /$1/$2/$3/$4/$5 [L,NC]

Redirecting Subdomain to Subfolder

I try to add the following logic to a .htaccess file:
subdomain.domain.xx make a redirect to subdomain.domain.xx/subdomain/
xy.domain.xy redirect to xy.domain.xy/xy/ (it should work with every subdomain without adding new rewrites)
i found a lot of solutions to redirect subdomain.domain.xx -> domain.xx/subdomain, but nothing like i need... below you find the code i try out.
Hope someone can help me. Thanks.
RewriteEngine on
RewriteBase /
RewriteRule ^([^.?]+[^.?/])$ $1/ [R]
RewriteCond %{HTTP_HOST} ^(www)?.domain.ch/$
RewriteRule .* http\://%1$1.domain.ch/%1$1 [I,R=301]
Place this in the .htaccess file of your subdomain's root directory:
DirectoryIndex index.html
RewriteEngine on
Redirect permanent /index.html http://subdomain.domain.xx/subdomain/

Resources