Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I'm having a bit of a fit here. I'm wading into the vast pool of .htaccess in order to rewrite my URLs to be SEO friendly.
I have been researching this all day. I take code snippets from various tutorials and SO posts, yet I get no results and most of the time, no errors.
I have a cPanel dedicated server running Apache 2.0. I called my host, LunarPages, and verified that mod_rewrite was installed and it is, and apparently is working fine.
where I'd like to start is changing the name of index.php to /home/ as in http://www,website.com/home/ making the trailing slash optional as well as home being case insensitive.
Literally, everything I try is doing nothing, it's as though the request is being ignored completely.
I'm writing the .htaccess file in Notepad on my PC and uploading it with FileZilla with the transfer type set to ASCII.
where I'd like to start is changing the name of index.php to /home/ as in http://www,website.com/home/ making the trailing slash optional as well as home being case insensitive.
Try:
RewriteRule ^/?home/?$ /index.php [L,NC]
Note that if you have any relative links (like to scripts or CSS) in index.php and you go to http://www,website.com/home/, the relative links will have /home as a base (instead of /). And you'll either need to make those links absolute or add a URI base to the page header:
<base href="/">
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Hi I'm trying to sync local files to a remote server, the files are copied, but the excluded files are not working.
What I want to exlude is some files, under some different folders for example:
htdocs/index.php
htdocs/.htaccess
htdocs/conf/Configuration.php
rsync -arvz --no-links --exclude-from 'excluded-files.txt' ./htdocs/ user#host:/var/www/test/htdocs/
What's going wrong?
Unless you are using -R, the exclude patterns are matched against the subdirectories of the from directory. In your case you must exclude index.php rather than htdocs/index.php, but that might match too many such files. By adding -R instead, the name you will test against will be ./htdocs/..., so the patterns will work, but you then need to remove htdocs from the destination directory, i.e. user#host:/var/www/test/
I want to remove numbers on the end url in specified folder, using htaccess.
(Numbers and minus sign befor numbers). For all urls in this folder.
For example
http://www.example.com/music/new-track-released-52
or
http://www.example.com/music/helo-there-4
Need to look like
http://www.example.com/music/new-track-released
http://www.example.com/music/helo-there
For all links in folder music
(I'm already removed php extension with htaccess)
How to do that?
Probably something like this:
RewriteEngine on
RewriteRule ^/music/(.+)-[0-9]+$ /music/$1
Note that this is the version for the host configuration. For .htaccess style files this has to be slightly modified. Whenever possible you should prefer not to use .htaccess style files but the real host configuration instead. Those files are notoriously error prone, hard to debug and really slow the server down.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have moved to php software that creates SEF URLs. But my site has been around a long time and there are many Not Found errors that come in for old URLs that have the htm extension. Is there a way to direct any URL with the .htm extension to, say, the home page of the site?
This will redirect any URL that ends with .htm or .html to the homepage and if you remove l? it will redirect only .htm.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^(.+?)\.html?$ /? [R=301,L]
Keep in mind if you have other rules on your .htaccess it may conflict with those rules and I would have to see it as the way its done might need to be different to work without conflicting with your current rules.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Now that my feet are officially wet with .htaccess I have a new question. In one of the many tutorials I have bookmarked, the author recommends placing this bit of code at the beginning of the .htaccess file:
AddDefaultCharset UTF-8
RewriteEngine On
RewriteBase /
I can understand the issues of avoiding parsing issues with that first line, so what I want to know is, aside from RewriteEngine On are the other two lines good practice or just adding bloat?
Many thanks!
The RewriteBase / line is sometimes used to resolve relative URIs in the target and/or patterns of RewriteRule's. For example, if an htaccess file is in the /foo directory, and you have rules that might look something like this:
RewriteEngine On
RewriteBase /foo/
RewriteRule ^bar$ index.php?bar [L]
Here, the rule's target index.php?bar is a relative URI and the base gets prepended to it, resulting in the URI: /foo/index.php?bar. When the rule's target is relative, apache will make a guess as to whether the URI is a file-path or a URL-path, and it doesn't always guess correctly. With the RewriteBase /foo/, apache knows that the /foo/index.php is a URL-path. There could be instances where the rewrite base doesn't match the folder that it's in, but the result is still the same. It acts as a URI base for the relative URI's that are in the rules.
Having it doesn't hurt, unless for some reason you want certain relative URI's to actually map to file-paths.
The AddDefaultCharset directive doesn't apply to the character set of the htaccess file, it's part of the response that the webserver gives to requests when the requested content is of type text/html or text/plain. Again, doesn't hurt to have this in your htaccess file unless you're text or html content is actually some other encoding (like *shift_jis* for example).
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I'm pretty new to .htaccess and I'm trying to rewrite the following URL structure:
http://www.example.com/groups/menu.php?id=This is Group Name With Number 25
into:
http://www.example.com/groups/this-is-group-name-with-number-25/
as you can see I need to include - as a separator instead of empty spaces, and I also need to have all characters be lowercase, but allow numbers.
Now since "This is Group Name With Number 25" is user-generated, do I need to make any additional changes within my PHP script so it can generate that kind of URL in web browser or will the .htaccess file handle everything?
You can use external rewriting for such things. This one will be a simple few-line perl script. See apache documentation for "External Rewriting Program".
RewriteMap mapname prg:/path/to/program
You should be handling a path creation like that in PHP, before it even gets sent to the HTML and into an anchor for someone to click on. Not only does it contain spaces which will get converted into %20 and make the URL unreadable, it contains uppercase letters!
There is no efficient way to lowercase your letters and replace all the spaces with dashes efficiently. Most methods will use a bunch of extra HTTP requests.