URL Rewrite index.php?domain=domain.com to /domain.com - .htaccess

I have .htaccess this
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^([^/.]+)$ index.php?domain=$1
If url domain.com/goo is show the result, but if url domain.com/goo.gl is not found, whats wrong?

I am unable to comprehend your current rule you are trying to remove "." in matched string even though the rule is incorrect try with below we are matching the string fully leaving none.
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^(.+)$ index.php?domain=$1

Related

Redirection old site with get variables

In htaccess file, i need to redirect all old site urls to a new one.
My actual redirection recup just the page url in a get variable (source)
I need to add a second variable (hotel) to recup it if it exists.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ http://newsite.com/page/?source=$1 [R=permanent,L]
You can use:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ http://newsite.com/page/?source=$1 [R=permanent,QSA,L]
QSA|qsappend : When the replacement URI contains a query string, the default behavior of RewriteRule is to discard the existing query
string, and replace it with the newly generated one. Using the [QSA]
flag causes the query strings to be combined.
http://httpd.apache.org/docs/current/en/rewrite/flags.html#flag_qsa

Laravel clean URLs

Working on a Laravel project and trying to get a simple URL rewrite working. Here is the .htaccess file, located in the '/public' folder — you can see I have added one rule
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# above is default, rule added by me:
RewriteRule ^articles/page/([a-zA-Z0-9-/]+)$ /articles?page=$1 [L]
</IfModule>
However, this just 404s. I suspect the default rule is breaking it somehow but don't know enough to fix it.
Can anyone help, please?
It would appear to me that your rule to convert articles/page/{slug} into articles?page={slug} is never hit. Because the rule is the bottom-most and your index.php rewrite rule says it's the "last" rule ([L]) and matches anything it wins every time (i.e. there's never any fall-through to your new rule).
Move your articles-specific rule between RewriteBase and RewriteCond and don't mark it as the last rule (get rid of [L]) and try again. That should transform articles/page/{slug} into articles?page=slug and then pass that on to the index.php rule.
You may also need the QSA rewrite rule option to make sure the query string you create works with any query string that exists already.
See:
http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
http://httpd.apache.org/docs/current/rewrite/flags.html
Try changing order of your rules:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
# above is default, rule added by me:
RewriteRule ^articles/page/([a-zA-Z0-9/-]+)/?$ /articles?page=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Or you can use Laravel's routes:
Route::get("/articles/page/{article}", "ArticleController#showArticle")
->where("article", "[a-zA-Z0-9/-]+");
And the controller:
class ArticleController extends Controller {
public function showArticle( $articleID ) {}
}
I think this is a better approach.

Simple Htaccess redirect not working

For some reason this is not working...
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /
Redirect 301 "/modules.php?name=News&file=article&sid=179" http://www.mysite.com/a/new/url
I have no idea why... If I replace the URL being redirected with another non-existent one (/helloworld) it redirects fine to the new url..
Is it catching on something? I tried escaping (/modules.php\?name=News&file=article&sid=179) but it didn't make any difference, still just 404s.
any help is appreciated!
You can't match against the query string in the Redirect directive, you'll have to use mod_rewrite and the %{QUERY_STRING} variable. Try this:
RewriteCond %{QUERY_STRING} name=News&file=article&sid=179
RewriteRule ^/?modules\.php$ http://www.mysite.com/a/new/url? [R=301,L]
# There is a ? here to prevent query strings appending -----^

How to define this RewriteRule in .htaccess

I want to rewrite the following url into another one.
domain.com/abc to domain.com/news.php?name=123
I defined the following rule in my .htacesss file.
RewriteRule abc /news.php?name=123 [PT]
It works but I only want "domain.com/abc" rewrite to /news.php?name=123
What I have now will match any words which contains "abc" and rewrite to destination.
Any suggestions?
RewriteEngine on
RewriteRule ^abc$ news.php?name=123
Hopefully this should work. Let me know if it doesn't.
Try below:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^abc news.php?name=123

Rewrite url with query string in htaccess

Today I try to rewrite some ugly url in order to be cache by browser! But the problem is that I have multiparameters inside the url. An example is better than a long text :
the actual url with the ? and the & :
http://images.mydomain.com/lib/simple-thumb.php?src=http://google.com&l=180&h=135&zc=1
And I want to use this instead :
http://images.mydomain.com/lib/http://google.com/180/135/1
Should I use the rule below in my .htaccess?
Options +FollowSymLinks
RewriteEngine On
rewritecond %{query_string} ^(.*)$
rewriterule simple-thumb\.php /lib/%1/? [R=301,L]
But not seams to be work...
Thanks for your kind help
Try
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/lib/http\:\/\/google.com/([0-9]+)/([0-9]+)/([0-9]+)$ /lib/simple-thumb.php?src=http://google.com&l=$1&h=$2&zc=$3

Resources