Htaccess rewrite working but without query string - php

I have a simple rewrite that works on localhost but not on my server. I'm trying to rewrite
www.website.com/arrangements/garden
to
www.website.com/arrangements.php?link=garden
and the code I have is
RewriteEngine On
RewriteRule ^arrangements/(.*)/?$ arrangements.php?link=$1 [NC,L]
But what I get on the server is only arrangements.php. The query string link is not present. I've tried everything I could think of and contacted hosting support as well, they got nothing.
Any ideas?

Use this,
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^arrangements/(.*) arrangements.php?link=$1 [L]

Related

.htaccess rewrite getting url not found

I am trying to rewrite URL's using .htaccess methods. This is working on localhost when XAMPP is used, but when I put it on the server it just doesn't.
Here is an example of the code used:
RewriteEngine On
Options +FollowSymLinks
Options -Indexes
DirectorySlash Off
RewriteRule ^contacts?$ contacts.php
RewriteRule ^example?$ tester.php?number=1
RewriteRule ^anotherexample?$ tester.php?number=2
I get this error message:
The requested URL /AMENPTHOME/hostnd/b/5/6/b56a95b8c/www/htdocs/public/new/produto_individual.php was not found on this server.
Can someone help?

URL rewrite rule is not working in php

i am using godaddy hosting and addon domain. i want to make my long url to short url.
for example my url is follwing:
www.example.com/events/landing_event.php?url=text-first
and i want following url:
www.example.com/events/text-first
for this i am using following rewrite url in .htaccess file
RewriteRule ^([a-zA-Z0-9-/]+)$ events/landing_event.php?url=$1 [L]
RewriteRule ^([a-zA-Z0-9-/]+)/$ events/landing_event.php?url=$1 [L]
but this rewrite rule is not working.
so please help how can i make short url.
Use this source after you make sure RewriteEngine Enabled and On
RewriteEngine On
RewriteRule ^events/([^/]*)$ /events/landing_event.php?url=$1 [L]
The original URL:
http://www.example.com/events/landing_event.php?url=text-first
The rewritten URL:
http://www.example.com/events/text-first
Updated with 500 Internal Server Error
Your code is guaranteed to generate 500 internal server error because it is causing infinite looping. Reason is that your matching URI pattern is: ^events/([^/]*)$
Which matches your URLs before and after rewrites. And once it reaches max allowed internal rewrite limit Apache throws 500 internal server error and bails out.
Change your code to this
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^events/([^/]*)$ /events/landing_event.php?url=$1 [L,QSA,NC]
Try this code :
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /events/landing_event.php?url=$1 [L]
Add this in your .htaccess file
You can see there are many ways to achieve that goal.
Also
RewriteEngine On
RewriteRule ^events/([^/]*)\.html$ /events/landing_event.php?url=$1 [L]
would do the job. So basicly, how does the full scope of your project urls look like?
Like do you always want to print the parameters? If yes, also the name sometimes or also the value?
The newer versions of apache requires you to change AllowOverride on /etc/apache2/apache2.conf
from
AllowOverride None
to
AllowOverride All

Cant redirect my URL with htaccess

I am using WAMP and my url is localhost/hotel/hotels.php?id=21
Using rewrite rule as follow,
Options +FollowSymLinks
RewriteEngine on
RewriteRule hotels/id/(.*)/ hotels.php?id=$1
RewriteRule hotels/id/(.*) hotels.php?id=$1
But nothing happens..
My mod_rewrite is on and also changes done in httpd.conf file.
Please give me a suggestion to handle the issue?
You must use flags for your RewriteRule. You can change it as follow
RewriteEngine on
RewriteRule ^hotels/id/([\d]+)/?$ hotels.php?id=$1 [NC,L]
You can call your pages from
localhost/hotel/hotels/id/12
If your .htaccess file is located in localhost/hotel .

Hide a part of a URL with mod_rewrite but keep the argument

I would like to write a rule where the members/show/ string will be hidden in the URL.
The original URL: localhost:8080/sandbox/member/show/helloworld, where helloworld is the name of the account. I'd like it to be localhost:8080/sandbox/m/helloworld. Basically, the content delivered will be from the full url, but I'd like it to be hidden for any user.
RewriteRule ^.*$ member/show/$0 [L,QSA] doesn't seem to work, it throws a 500 Internal Server Error. I work with the CodeIgniter Framework, and the following rewrite rule is already present: RewriteRule .* index.php/$0 [PT,L].
I tried several RewriteRule options but without success. I'd be very glad if anyone could shed some light related to my question.
Best regards.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(sandbox)/m/([^/]+)/?$ /$1/member/show/$2 [L,NC]

Creating friendly URLs with mod_rewrite in htaccess?

I have searched this forum and have done extensive google search and have not been able to figure it out. I have many links that look like:
mysite.com/example6.php?id=play-game
mysite.com/example6.php?id=watch-tv
mysite.com/example6.php?id=go-outside
I have tried lots of different code putting this in my .htaccess file:
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /example6.php?id=$1 [L]
and
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^id/(.*) example6.php?id=$1
</IfModule>
and many more attempts but nothing works to get my URLS to look like this:
mysite.com/example6/play-game
mysite.com/example6/watch-tv
mysite.com/example6/go-outside
I do have mod_rewrite enabled on my server. Does anyone have any ideas?
Try this:
RewriteRule ^example6/(.*)$ example6.php?id=$1 [L]
Your first example (RewriteRule ^([^/]*)\.html$ /example6.php?id=$1 [L]) would correctly work for urls like "/play-game.html", and your second example (RewriteRule ^id/(.*) example6.php?id=$1) would correctly work for urls like "/id/play-game".

Categories