force index.php in url with htaccess - .htaccess

I've spent the last two hours reading stackoverflow and the apache manual trying to find a solution to this, but haven't found any, if a directory is access (http://domain.ext) I'd like to force index.php to appear in the url (http://domain.ext/index.php) if possible.
If anyone could help I'd really appreciate it, thank you.
RewriteEngine on
RewriteRule index.php

you can use this:
RewriteEngine on
RewriteRule ^$ /index.php?
(but you will not see it in a browser because the rewrite engine just directs to the correct file/directory without changing the url from the browser)
with [R] tag you can redirect the user so the new url would appear in the browser

I've just found what works for me
RewriteEngine On
RewriteRule ^/?$ $1/folder/index.php$2 [R=301,L]

Related

htaccess is working but does not replace the url

I'm trying to modify the subdomain name in the URL to make it look nicer. My current URL look something like:
www.mystore.com/productInfo.php?cPath=11_11&productID=222
So, I want to make it nicer by Rewrite in .htaccess in main with this code:
RewriteEngine On
RewriteRule ^productInfo/([0-9_-]+)/([0-9_-]+) productInfo.php?cPath=$1&productID=$2 [NC,L]
When I run and test it on the URL by typing www.mystore.com/productInfo/11_11/222 in the URL it works well. However, when this page is redirected by a different page or is 'refreshed' with a self redirecting a href= link(in which the link is written in php by the previous programmer), the above old link is still visible in the URL instead of the new one.
I am still a beginner while I suspect that I might need to change something in the cPanel/Apache(I think) for this but currently, I am still do not have access to the cPanel control. Is there anything that I might have missed to write in the .htaccess file or I really do need the cPanel control or any other reasons?
Any help is appreciated. Sorry that I could not find similar questions on this.
You can use the following :
RewriteEngine On
RewriteBase /
#redirect /productInfo.php?cPath=foo&productID=bar to /productInfo/foo/bar
RewriteCond %{THE_REQUEST} /productInfo\.php\?cPath=([0-9_-]+)&productID=([0-9_-]) [NC]
RewriteRule ^ productInfo/%1/%2? [L,R=301]
#rewrite new URL to the old one
RewriteRule ^productInfo/([0-9_-]+)/([0-9_-]+) productInfo.php?cPath=$1&productID=$2 [NC,L]

Redirect Specific non-existing URL to an existing

I have a simple need to redirect:
mypage.com/myurl (which doesn't not exist; meening that returns a 404 error)
To
mypage.com/newurl/myurl (which is an exitsing page with content).
I saw a tons of forum post about this, but didn't find an awnser. I tried lot of thinks but with internal server error, infinitive loops etc.
Please note that I have a www to non www permanent redirect, like this:
RewriteCond %{HTTP_HOST} ^www\.mypage\.si [NC]
RewriteRule ^(.*)$ http://mypage.si/$1 [L,R=301]
UPDATE:
I will be specific:
This URL doesn't exist: http://domodom.si/sl/nepremicnine
and needs to be redirected here: http://domodom.si/sl/nepremicnine/nepremicnine-ponudba
Hope this will offer more insights about the problem.
Thanks
assuming mod_rewrite
RedirectPermanent /myurl/ mypage.com/newurl/myurl
Add this to your .htaccess file
RewriteBase /
RewriteRule ^(.*)$ newurl/$1 [NC,L]
you may want to try implementing the answer of nwellnhof in this thread.. it worked for me..

Mod_Rewrite with .htaccess is not working

I just learnt about url-rewrite for my website with .htacess. My actual url is:
localhost/index.php?view=some-page
So i write this RewriteRule like this:
RewriteRule ^/([^/]*)/?$ /index.php?view=$1 [NC,L]
When i typed localhost/homepage on my browser, It does not work, it displays error 404 object not found. What have i done wrong please show me.
Many thanks
This should work in your DocumentRoot/.htaccess:
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)/?$ index.php?view=$1 [QSA,L]
Leading slash is not matched in htaccess.
are you using apache?
This link from step 6 helped me
https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-on-ubuntu-14-04
When i was playing around with rewrites i had to enable it and tell apache where the pages were stored

Rewrite URL and permanently redirect to new URL

I've just spent the last 2 hours trawling through Google and the Stackoverflow archives to see if I could find an answer to my question and instead of finding nothing, I've found too much! So unfortunately I'm having to add to the mountain of 301 redirect questions. Sorry. And thanks for taking a look at this one ;)
Basically, I've got a blog for which I'm looking to simplify the URL. Currently the URLs look like this:
http://tempertemper.net/post.php?s=2012-05-30-freeagent
I'd like them to look like this:
http://tempertemper.net/2012-05-30-freeagent
I've tried adding RewriteRule /(.*)$ /post.php?s=$1 to my .htaccess file but it's not having it.
The full file currently looks like this:
<ifModule mod_rewrite.c>
DirectoryIndex index.php index.html
ErrorDocument 404 http://tempertemper.net/error.php
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.tempertemper\.net$
RewriteCond %{REQUEST_URI} !cron.php
RewriteRule ^(.*)$ http://tempertemper.net/$1 [R=301,L]
</ifModule>
I've tried adding this after the canonicalisation bit that redirects www. to non www.:
RewriteRule ^([a-zA-Z0-9_-]+)$ post.php?s=$1
It sort of works. I can then link to http://tempertemper.net/2012-05-30-freeagent but the problem is, http://tempertemper.net/post.php?s=2012-05-30-freeagent still exists. This is more than likely bad for seo as I guess I'll have duplicate content, in the eyes of the search engines. I've tried putting a [R=301] on the end of the new line but it stops the new link working. Also tried putting the ,L in the square brackets and removing it from the canonicalisation command, but no joy (L is for last command, isn't it…?).
Basically, I'm after all URLs that generate or have generated with post.php?s= in them to permanently redirect to the ones without post.php?s= so that any links that come in to those pages already are redirected and any links in the future will direct straight to the new-look URL.
Hope that makes sense…
Thanks,
Martin :)
Apache actually fixes local paths => proper fully qualified names (my original assumption), but I see that your file actualy checks for the wrong files. Using your supplied file I think this will work as the file contents:
DirectoryIndex index.php index.html
ErrorDocument 404 http://tempertemper.net/error.php
RewriteEngine On
# don't redirect post.php to itself
RewriteCond %{REQUEST_URI} !post.php
# don't redirect error.php to post.php
RewriteCond %{REQUEST_URI} !error.php
RewriteRule ^(.*)$ "/post.php?$1" [R=301,L]

Using .htaccess and mod_rewrite

I'm having some mod_rewrite problems with my .htaccess..
RewriteBase /folder
RewriteEngine on
Rewrit­eRule ^(.*)$ basic.p­hp?­url=$1 [L]
Above is what I'm currently using. However, I have no idea what I'm doing to be honest as I'm just cycling through the internet trying to figure this out.
Basically, for my website, if you type in
www.domain.com/folder/xxx/
I want it to basically be www.domain.com/folder/basic.php?url=xxx.
For some reason, all that does is cause a 404 error :/
So can someone please politely point me in the right direction?
Ok, I will explain using your htaccess.
RewriteEngine on
Turn on the Rewrite Module to enable URL rewriting
RewriteBase /folder
Rewrite the Base Directory to directory name folder
RewriteRule ^folder/(.*)$ basic.php?url=$1 [L]
Remap every request make using the folder/***** to basic.php?url=********
Note: RewriteEngine On Should be the first statement on your case
RewriteEngine on
RewriteBase /
RewriteRule ^folder/(.*)$ folder/basic.php?url=$1 [L]
This is more of a problem with regexs than .htaccess files.
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
http://www.regular-expressions.info/

Resources