.htaccess Rewrite rule not working - wildcards - .htaccess

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]

Related

rewrite url /blog/article.php?id=hello to /blog/hello.html

Im having some troubles with the redirection rules on my .htaccess file.
I would like to create a rule to redirect my blog content to a friendly url.
The current url structure is:
/blog/article.php?id=hello
and I would like it to change to:
/blog/hello.html
This are my rules so far, and I dont seem to be able to find the error:
RewriteEngine On
Options -MultiViews
RewriteRule ^blog/([a-z,A-Z,0-9]+)$.html blog/article.php?id=$1 [L]
Any help would be appreciated.
Because of your placement of $ in the pattern, the rewrite module is unable to match your request to the expression.
It should be:
Options -MultiViews
RewriteEngine On
RewriteRule ^blog/([\da-z]+)\.html$ blog/article.php?id=$1 [L,NC]

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]

in htaccess first folder is not working with dashes

I have URL like this: http://example.com/apple_a/
I am using this rule:
RewriteEngine On
RewriteRule ^([^_]*)-+(.*)$ $1_$2 [L,NC]
this is replacing other URL's like http://example.com/apple/a_a/a_b to "http://example.com/apple/a-a/a-b" (underscore with dashes) but when I write "_" in first directory like this "http://example.com/apple-a/a-a/" then its throwing 404 error.
So I wants that working somehow. Please help.
Correct rule will be:
RewriteEngine On
RewriteRule ^([^-]*)-+(.*)$ $1_$2 [L,NC]
You have ([^_]*) instead of ([^-]*)

Why my htaccess rule is not working unless it's directed to a PHP file

My htaccess file is under "myappname" folder.
I'm trying to redirect this path;
myappname/CONTROLLER_NAME/ANYFILE.(css|js|gif|jpg|png)
To that path
myappname/views/default/tpl/CONTROLLER_NAME/ANYFILE.(css|js|gif|jpg|png)
and this is my HTACCESS rule
RewriteEngine on
RewriteRule ^(.*)/(.*)\.(css|js|gif|jpg|png)$ views/default/tpl/$1/$2.$3 [L,NC]
but it's giving me HTTP 500 unless I redirect it to a PHP file like
RewriteEngine on
RewriteRule ^(.*)/(.*)\.(css|js|gif|jpg|png)$ views/default/tpl/$1/index.php?a=$2.$3 [L,NC]
What is wrong with my rule? I'm very new to htaccess and there is a very big potential to I'm missing something small.
This is because your target matches the regex:
views/default/tpl/foo/bar.png
matches the regex:
^(.*)/(.*)\.(css|js|gif|jpg|png)$
So the rules just keep looping. You need to add a condition:
RewriteCond %{REQUEST_URI} !^/views/default/tpl
right above your RewriteRule.

Matching a URL in 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

Resources