mod_rewrite redirect folder to URL - mod-rewrite

I've been trying for the last few hours to do something that seems simple..
http://www.mydomain.com/u/username
redirect that to
http://www.mydomain.com/goto.php?u=username

In apache or IIS?
in apache you could use an .htaccess with (in the u folder)
RewriteEngine on
RewriteRule ^([^/]*)/([^/]*)/$ goto.php?u=$2 [L]
If on IIS and you have the latest version, you can import .htaccess into it quite easily with a tool that comes with it

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^u/(.*)$ goto.php?u=$1 [L]
</IfModule>
Edit: To redirect using a HTTP 302/301 response use this:
RewriteRule ^u/(.*)$ goto.php?u=$1 [R=301,L]
or
RewriteRule ^u/(.*)$ goto.php?u=$1 [R,L]

Related

Why my .htaccess in codeigniter is different

All of my .htaccess in codeigniter like this
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
But all tutorial .htaccess are like this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I need help to remove index.php url in codeigniter.
Why should I replace all code .htaccess like tutorial said ?
Should you replace all code .htaccess like tutorial said ?
Yes! just in the root directory of your CodeIgniter project.
Why?
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
The CodeIgniter documentation says that by the rules given in .htaccess file, any HTTP request other than those for index.php, images, and robots.txt is treated as a request for your index.php file.
without these rules, for example, you'll have to access your login page like this
http://yourdomain.com/index.php/<controllerName>/login
with the rules in .htaccess file it's
http://yourdomain.com/<controllerName>/login

mod_rewrite one url string

Can somebody tell me how to get mod_rewrite to rename this:
our-work-section.php?id=3&title=something
to
our-work-section/something/3
Right now my .htaccess is in directory C:\workspace\www\brown, My vhost is setup for http://workspace/, So I did a RewriteBase below. I currently Have:
RewriteEngine On
RewriteBase /www/brown/
RewriteRule ^/our-work-section/?$ our-work-section.php?id=$1 [NC,L]
My error log isn't saying anything, and the page doesn't do anything. I've tried toggling slashes / here and there.
Try this one
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(our-work-section)/?$ /our-work-section.php?id=$1 [L]
EDIT
This one will work. I tested it
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(our-work-section)/([^/\.]+)/?$ /our-work-section.php?id=$1 [L]

.htaccess "Ignore all rules if link starts with..."

In my root folder I have installed wordpress and there is also my submenu.php that can not be loaded with ajax if I use rules for /%postname%/ (in default )
So this is what WP gave me
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress
What do I need to add so that calling
$('#submenu').load('submenu.php?cat=4');
works again?
This is not the way you should be performing AJAX within WordPress.
I suggest you read up on Using AJAX within WordPress from the codex.
I am not really good with htaccess, but this
RewriteRule !^media/ index.php [L]
Will redirect everything except media/* to index, so something like this should work
RewriteRule !^yourscript.php index.php [L]
Note: I agree with Jason there, using it without htaccess is better.

RewriteRule help directing to and from http/https

In my Apache config file, I have the following to redirect to https if the page name has login in it:
<VirtualHost 1.2.3.4:80>
-- snip --
RewriteEngine On
RewriteRule ^/(.*)login(.*) https://domain/$login$2 [L]
</VirtualHost>
And here is the part that I am having troubles with. I want to redirect every page that does not match ^/(.*)login(.*) back to http.
<VirtualHost 1.2.3.4:443>
-- snip --
RewriteEngine On
RewriteRule ^/(.*) http://domain/$l [L]
</VirtualHost>
But as I have it, I created a circular rewrite.
What am I missing?
p.s., the IP 1.2.3.4 is bogus. :)
Not tested, but should work with:
RewriteEngine On
RewriteRule ^(.*)login(.*) https://domain/${REQUEST_URI} [L]
RewriteRule (.*[^l][^o][^g][^i][^n].*) http://domain/${REQUEST_URI} [L]
Maybe you can also forget the matching of (.*[^l][^o][^g][^i][^n].*) qnd replace by .* since the [L] should stop the HTTPS request from being match after their rewite rule. To be tested.
This solved my issue:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(.*)login(.*)
RewriteRule ^/(.*) http://domain/$1 [L]

how do i rewrite www.domain.com to another domain's /www/domain.com/index.php?

i have this on my htaccess currently:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/www/
RewriteRule (.*) /www/$1/index.php
but i keep getting an error page
what im trying to do is to register a lot of domains for clients
and just store all their websites' files on a folder named "theirdomain.com" on my domain's www folder.
Firstly you will never find www in the URI BEcause the URI is everything after index.php? so the uri will be index.php?/here/is/the.uri/string
I would look at HTTP_HOST
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} !^first-host.com$ [NC]
RewriteRule ^(.*)$ http://new-host.com/$1 [L,R=301] #Send 301 so search engines know where to go.
</IfModule>

Resources