rewrite url using htaccess file? - php

I want to rewrite this url
http://localhost/vector-svn/demo.php
rewrite to
http://localhost/vector-svn/demo
my .htaccess file code
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.$ $1.php [nc]
any kind help would be appreciated ?

Answer to my own question !!
This works for url rewriting !!
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

You could do this:
rewriteRule ^(.*)$ $1.php [NC]
Edit: I see your rewrite rule is exactly the same. What problem do you have?

Sounds like mod_rewrite is not installed at all. Check apache documentation, link.
Sorry, brief answer... this link might also help you out, could be a few things and as mentioned the rewrite looks fine, so try and see if any of the following work.
http://www.wallpaperama.com/forums/how-to-fix-mod-rewrite-500-internal-server-error-on-htaccess-file-apache-t718.html

Related

Rewrite Url at my website but my index on sub folder

I've been crawling forums for about 2 hours and still haven't found the solution to my problem so I am turning to you guys for help.
My URL looks like this
http://sevalinmutfagi.com/list.php?id=1?kategori=borekler
I want it to look like this
http://sevalinmutfagi.com/tarifler/borekler
I try so much rewrite example but my index file at a subfolder in /View/ so I can't rewrite my URLs
here my .htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?sevalinmutfagi.com$ [NC]
RewriteCond %{REQUEST_URI} !^/View/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /View/$1 [L]
RewriteCond %{HTTP_HOST} ^(www.)?sevalinmutfagi.com$ [NC]
RewriteRule ^(/)?$ View/index.php [L]
This code works well for redirect subfolder all pages but I try to add rewrite URL codes can't work. I hope that has been revealing. Thanks to every for help.
that's worked for me fine.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/subfolder
RewriteRule ^(.*)$ /subfolder/$1 [NC,L]
The FIRST thing to learn about mod_rewrite is when NOT to use it. Since mod_alias handles your specific task very nicely, that’s what I’d use:
Redirect 301 / /subfolder/
Since that looks like it would be “loopy,” you could fall back on mod_rewrite:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^subfolder/
RewriteRule .? subfolder%{REQUEST_URI} [R=301,L]
There’s just too much wrong with your attempt to cover … and I’ve addressed exactly those issues many times in many threads. Therefore, you might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It’s helped may members and should help you, too

Can not Rewrite a URL with my .htaccess file

I'm having trouble rewriting a URL on my website to make it more presentable and easier to find on search engines.
I want to turn this:
http://www.gamingpopulace.com/threads/index?threadName=Glitches
Into this:
http://www.gamingpopulace.com/threads/Glitches
I'm currently using a .htaccess file with this in it:
RewriteEngine On
RewriteRule ^threads/([A-Za-z0-9-]+)/?$ /threads/threadName=$1 [NC,L]
From what I've seen seen in other questions, this should work.
What goes wrong:
When I type http://www.gamingpopulace.com/threads/Glitches into the URL, it just gives me a 404 error saying that the page is missing. From my understanding it should load http://www.gamingpopulace.com/threads/index?threadName=Glitches, but with the changed URL. Though I might be misunderstanding that.
Any help is appreaciated.
Thanks
Hello and welcome to SO
(I cheated and used Google but amended the info according to your question.)
Source : How To Set Up Mod_Rewrite
RewriteEngine on
RewriteRule ^thread/([A-Za-z0-9-]+)/?$ threads/index?threadName=$1 [NC]
Remove / from this ([A-Za-z0-9-]+)/?$
Replace
RewriteEngine On
RewriteRule ^threads/([A-Za-z0-9-]+)/?$ /threads/threadName=$1 [NC,L]
with
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule ^threads/([^/]*)?$ /threads/threadName=$1 [L]
I am assuming your original url is working, try this in root dir,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^threads/([\w-]+)?$ threads/index?threadName=$1 [QSA,NC,L]

.htaccess url rewriting not working?

I'll be honest in saying I have very little experience with .htaccess as I've always wanted to stay away from it as best I can. However, I've recently wanted to tidy up my urls and I've found that it's possible through .htaccess and rewriting.
Basically, I want to rewrite a url like:
www.mysite.com/profile.php?id=48194
To something like:
www.mysite.com/profile/48194
Here's the code I have currently:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^profile/(.*)/$ profile.php?id=$1
The line I'm trying to use is on the very bottom, RewriteRule ^profile/(.*)/$ profile.php?id=$1. The rest is used to remove the page extensions from the urls. I've changed $1 to $2 thinking perhaps it was conflicting with the code above, but nothing changed.
I also removed all the code except for RewriteEngine on and the last line thinking maybe the codes were conflicting but, again, nothing changed or worked. The rest of the code does work, removing the extensions from urls that is, so I know the rewrite thing is on.
Could someone try to break down and explain what I did wrong and how all this works? As well as providing a working example of the thing I'm trying to accomplish?
Thanks in advance!
Change order of your rules and use MultiViews option. Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php.
RewriteEngine on
RewriteBase /
RewriteRule ^profile/([^/]+)/?$ profile.php?id=$1 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteRule to redirect to php file not working

I just want a simple redirect to clean up the url's on a site.
e.g.
I want ajhtestserver.com/registration/ to redirect to ajhtestserver.com/registration.php
It should be easy and I have successfully used .htaccess rewrites on other sites but for some reason it just will not work for me today.
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^registration[/]$ registration.php [NC,L] # Handle requests for "registration"
I am sure it is something simple that I am missing but I basically just copied what I have on other sites that work fine for me so I am confused as to why it just refuses to work for me here (gives me The requested URL /ajhtestserver/registration/ was not found on this server. error). Just one of those days :(
Any help is appreciated.
Thanks,
Adam
if you use apache ,first you should enable rewrite_mode in http.conf or ...\
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^registration/(.*)$ registration.php/$1 [L]
check .htaccess syntax or rewrite mode.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)[/]$ $1.php [L]
Well it didn't seem to like it when the redirect source word and target filename were the same word but this works...
RewriteRule ^([a-zA-Z\ ]+)[/]?$ $1.php [NC,L]
And that is actually a better solution anyway as it doesn't require a separate rule for each page.
Though I never did figure out why it didn't like it the original way.

Rewrite rule looping indefinitely

I have strange problem with .htaccess I can't solve:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1
RewriteRule watermelonurltest wmelon/core/works.html
</IfModule>
When watermelonurltest is accessed, it loops to something like:
http://localhost/w/watermelonurltest/index.php/2/index.php/2/index.php/2/index.php/2/index.php/2/index.php/2/index.php/2/(...)
Which suggests that RewriteRule ^(.*)$ index.php?/$1 is applied instead of RewriteRule watermelonurltest wmelon/core/works.html
I tried to swap these two rules, but then other problems like this one occur.
The problem didn't exist when the first rule was
RewriteRule ^(.*)$ index.php/$1
(no question mark after .php)
For some reason, this question mark breaks it.
I can't figure out why this happens and how to fix it - I tried googling a little, but I didn't find anything helpful.
Thanks in advance.
https://www.communitymx.com/content/article.cfm?cid=51C62&print=true
I attempted to reproduce this in a fresh setup, but using the .htaccess and rules provided, I didn't encounter a loop; the rewrite was to index.php?/watermelonurltest; confirmed by looking at the rewrite log.
What redirection does index.php do, if any?

Categories