I'm new to rewriting urls and wanted to know how i would rewrite
From this
/profile/4
To this
/profile.php?id=4
I have this rule so far
RewriteRule ^profile/([0-9]+)/?$ profile.php?id=$1
but it displays this in the browser
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
It displays /profile/4/index.php in the browser address bar which is incorrect.
.htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
Options +FollowSymlinks
RewriteEngine on
#ErrorDocument 404 /test.php
DirectoryIndex test.php
RewriteRule settings editProfile.php
RewriteRule update update.php
RewriteRule home test.php
RewriteRule ^profile/([0-9]+)/?$ profile.php?id=$1
You are pretty much there. Try using this instead
RewriteRule ^profile/(.*)$ profile.php?id=$1
I found this good free resource online to help you test your rewrite rules before you post them to your live site. This may help for the future. It looks like your rule should work as you have it posted though. The problem must be somewhere else.
Your rule is just fine so there's a redirection somewhere conflicting with it. I suppose that you don't have a real directory at /profile/4 so they main candidate left is mod_negotiation. Try this:
Options -MultiViews
Related
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
I need help with something I don't understand.
I am developing a website for a customer.
I am doing on local, and every day upload to the server all changes and new things.
Last I done is create a simple way to extract the section, parameters and values from url. Is something like:
http://mywebsite.com/product/color/red
Really is not a shop, but this example shows clearly I want to tell you.
The idea is that I have a folder with the sections (product.php, home.php, contact.php, ...) and the section on url says the file to use.
This is working on my computer.
But now I've uploaded all files (literally) to server and not is working.
Shows me a 404 error.
I think the problem is into .htaccess and the PHP versions (I works on php 5.5.10 on local, and server runs on 5.4.16).
This is .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php?params=$1 [QSA,L]
</IfModule>
I don't know if you need something more information about all this. If you want, say it and I show you.
I hope you can help me.
Thank you!
UPDATE 2015 July 02
I tried a lot of thing and none worked.
Finally I tried to redirect to google, but not works. And I tried even break it with some wrong code into .htacces, but neither.
Searching I've read that the problem is AllowOverride is none.
For this I tried:
<Directory "/var/www/sites-public/laceart.cadt.com/html/">
AllowOverride All
Allow from All
</Directory>
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^test\.html http://www.google.com/? [R=301,L]
Still not working. But I don't know if Document Root is correct.
Can someone to help me?
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]
I have this URL pointing my web site:
http://www.mysite.ext/.htaccess.aspx-->/
and I like to redirected to
http://www.mysite.ext/
but I can't.
In my .htaccess file I have enter this rule:
RewriteRule ^(.htaccess(.+))/?$ http://www.mysite.ext/? [R=301,L]
but doesn't work
also I have try the following:
RewriteRule ^(\.htaccess\.aspx(.*))/?$ http://www.mysite.ext/? [R=301,L]
but still no luck. I don't know if that helps, but the site is based on PHP.
Any idea please ?
Is it realy so hard ?
Can somebody to help me please ?
Not sure how you are you getting requests for /.htaccess.aspx and why you want to redirect them.
However keep in mind that Apache configs usually block access to .htaccess using directive like below:
<FilesMatch "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>
That throws 403 (Forbidden) error for any request that starts with /.ht.
Workaround:
Have a custom handler for 403:
ErrorDocument 403 /errorPage403.php
and have this redirect rule:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+\.htaccess\.aspx [NC]
RewriteRule ^ /? [L,R]
I am using a PHP application I downloaded, and it is half working on my server, however I am having what I believe is a re-write error.
The application is a "job board" where people will be able to browse available positions, and apply online.
Currently it is "technically" working. A person can view the site, and postings, and they can fill out the application form. The message is sent properly.
The problem is that once the submit button is pressed the browser shows that the page is loading, but nothing ever loads. So the message is sent, but the following page is not loaded.
The application uses htaccess rewrites, and I believe this is where the problem is.
The application is supposed to work out-of-the-box on a top level domain, however I am trying to use it on a subdomain. Am I correct in assuming that technically there is not much difference when using a subdomain? After all, the pages all load fine until the form is submitted.
The application is running at http://volunteer.essentialtransit.com
What you see is the application after initially being set up, and I added one sample "job".
You can try applying to see the problem I am referring to. It is a very simple application form that only takes a few seconds to complete.
Here is the htaccess file:
# AddType x-mapp-php5 .php
# AddHandler x-mapp-php5 .php
RewriteEngine on
Options +FollowSymlinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
ErrorDocument 404 /page-unavailable/
<files ~ "\.tpl$">
order deny,allow
allow from none
deny from all
</files>
Perhaps if someone can explain what the htaccess rules are doing I can figure out the problem.
EDIT: So the page actually does load, but only after a very long time. The browser shows that the form is sent, and then following page starts to load, but then it takes minutes to actually load. All other pages on the site load quicker than that. The other strange things is that when a "job" page is initially opened it loads quick, after applying it just redirects back to the same "job" page, however this time it takes forever to load.
Rules are self explanatory:
RewriteEngine on # Enables rewrite engine (obviously)
Options +FollowSymlinks # Tells Apache to follow symbolic links
RewriteCond %{REQUEST_FILENAME} !-f # Here it redirects non-files
RewriteCond %{REQUEST_FILENAME} !-d # and non directories
RewriteRule . index.php [L] # to index.php
ErrorDocument 404 /page-unavailable/ # Sets 404 page address
<files ~ "\.tpl$"> # Denies access to templates
order deny,allow
allow from none
deny from all
</files>
I doubt your issues have something to do with these rules.